Skip to content

Setting and Inspecting Headers

Qriist edited this page Sep 17, 2026 · 6 revisions

Setting and Inspecting Headers

Setting Request Headers

SetHeaders configures custom HTTP headers for the outgoing request. It accepts two input forms:

Map / Object

Header names as keys, values as strings:

intentHeaders := Map(
    "Authorization", "Bearer abc123",
    "Content-Type", "application/json",
    "X-Custom-Header", "3"
)
curl.SetHeaders(intentHeaders)

Array

Pre-formatted "Header: value" strings:

intentHeaders := [
    "Authorization: Bearer abc123",
    "Content-Type: application/json",
    "X-Custom-Header: 3"
]
curl.SetHeaders(intentHeaders)

Special Values recognized by libcurl

Value Effect Example
"" (empty string) Disables an internally-used header Map("Proxy-Connection", "")
    or
["Proxy-Connection"]
";" (semicolon) Adds the header with no value. Map("Expect", ";")
    or
["Expect;"]

Retrieving Response Headers

GetLastHeaders() returns the headers from the most recent transfer as text. See Download Modes for the full encoding and sentinel parameter reference.

curl.SetOpt("URL", "https://httpbin.org/headers")
curl.HeaderToMem()
curl.WriteToMem()
curl.Sync()

headers := curl.GetLastHeaders()
MsgBox headers

Inspecting a Specific Header

InspectHeader returns the value of a named header from a specific connection in the transfer chain. This is most useful when redirects are involved, since each hop produces its own set of headers.

curl.SetOpt("URL", "https://httpbin.org/redirect-to?url=https%3A%2F%2Farchive.today")
curl.WriteToMem()
curl.Sync()

; Final connection (default, usually what you want)
finalDate := curl.InspectHeader("date")

; Initial connection (request index 0)
initialDate := curl.InspectHeader("date", , , 0)

The request parameter (fourth slot) targets a specific hop in the redirect chain. 0 is the first connection. Omitting it returns the last.

Enumerating All Headers

GetAllHeaders returns a complete array of every header received across all redirect hops. Use it when you need to iterate over the full set rather than targeting one by name.

curl.SetOpt("URL", "https://httpbin.org/redirect-to?url=https%3A%2F%2Farchive.today")
curl.WriteToMem()
curl.Sync()

redirectCount := curl.GetInfo("REDIRECT_COUNT")
allHeaders    := curl.GetAllHeaders()

MsgBox "Redirects: " redirectCount "`n`n"
 . curl.PrintObj(allHeaders)

The returned array has one entry per redirect hop (including the final destination). Each entry is an array of header objects.

Where to Go Next

Clone this wiki locally