curl / Mailing Lists / curl-users / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

HTTP response header access in curl

From: Daniel Stenberg via curl-users <curl-users_at_lists.haxx.se>
Date: Thu, 17 Mar 2022 22:43:17 +0100 (CET)

# HTTP response header access in curl

This support depends on the new headers API work coming in PR 8593. Hopefully
landing in 7.83.0.

This new header output is done with -w and new magic added to its abilties.

This is how it works right now. I'm showing it off early here because I like
it and it gives everyone a chance to voice opinions about the approach.

## Output individual header contents

Say hello to %header{name} where name is the case insensitive name of the
header withon colon.

$ curl -w '%header{date}\n' curl.se
Thu, 17 Mar 2022 16:59:24 GMT hello

## Output all response headers as JSON

Say hello to %{header_json}

$ curl -sw '%{header_json}\n' curl.se | jq
{
   "Server": "Varnish",
   "Retry-After": "0",
   "Location": "https://curl.se/",
   "Content-Length": "0",
   "Accept-Ranges": "bytes",
   "Date": "Thu, 17 Mar 2022 17:01:38 GMT",
   "Via": "1.1 varnish",
   "Connection": "close",
   "X-Served-By": "cache-bma1667-BMA",
   "X-Cache": "HIT",
   "X-Cache-Hits": "0",
   "X-Timer": "S1647536498.479515,VS0,VE0"
}


-- 
  / daniel.haxx.se
  | Commercial curl support up to 24x7 is available!
  | Private help, bug fixes, support, ports, new features
  | https://curl.se/support.html
-- 
Unsubscribe: https://lists.haxx.se/listinfo/curl-users
Etiquette:   https://curl.haxx.se/mail/etiquette.html
Received on 2022-03-17