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.
Re: HTTP response header access in curl
- Contemporary messages sorted: [ by date ] [ by thread ] [ by subject ] [ by author ] [ by messages with attachments ]
From: Daniel Stenberg via curl-users <curl-users_at_lists.haxx.se>
Date: Fri, 18 Mar 2022 00:00:09 +0100 (CET)
On Thu, 17 Mar 2022, Daniel Stenberg via curl-users wrote:
> $ curl -sw '%{header_json}\n' curl.se | jq
As was quickly pointed out to me on IRC, that format will not work for
duplicated headers - and such are still valid and frequently used. I think
header values therefor need to be made JSON arrays and thus rather look like
this:
{"Date":["Tue, 09 Nov 2010 14:49:00 GMT"],
"Server":["test-server/fake"],
"Last-Modified":["Tue, 13 Jun 2000 12:10:00 GMT"],
"ETag":["\"21025-dc7-39462498\""],
"Accept-Ranges":["bytes"],
"Set-Cookie":["firstcookie=want1; path=/","2cookie=want2;
path=/","cookie3=want3; path=/"],
"Content-Length":["6"],
"Connection":["close"]
}
... or when pretty-printed with jq:
{
"Date": [
"Tue, 09 Nov 2010 14:49:00 GMT"
],
"Server": [
"test-server/fake"
],
"Last-Modified": [
"Tue, 13 Jun 2000 12:10:00 GMT"
],
"ETag": [
"\"21025-dc7-39462498\""
],
"Accept-Ranges": [
"bytes"
],
"Set-Cookie": [
"firstcookie=want; path=/",
"2cookie=want; path=/",
"cookie3=want; path=/"
],
"Content-Length": [
"6"
],
"Connection": [
"close"
]
}
Date: Fri, 18 Mar 2022 00:00:09 +0100 (CET)
On Thu, 17 Mar 2022, Daniel Stenberg via curl-users wrote:
> $ curl -sw '%{header_json}\n' curl.se | jq
As was quickly pointed out to me on IRC, that format will not work for
duplicated headers - and such are still valid and frequently used. I think
header values therefor need to be made JSON arrays and thus rather look like
this:
{"Date":["Tue, 09 Nov 2010 14:49:00 GMT"],
"Server":["test-server/fake"],
"Last-Modified":["Tue, 13 Jun 2000 12:10:00 GMT"],
"ETag":["\"21025-dc7-39462498\""],
"Accept-Ranges":["bytes"],
"Set-Cookie":["firstcookie=want1; path=/","2cookie=want2;
path=/","cookie3=want3; path=/"],
"Content-Length":["6"],
"Connection":["close"]
}
... or when pretty-printed with jq:
{
"Date": [
"Tue, 09 Nov 2010 14:49:00 GMT"
],
"Server": [
"test-server/fake"
],
"Last-Modified": [
"Tue, 13 Jun 2000 12:10:00 GMT"
],
"ETag": [
"\"21025-dc7-39462498\""
],
"Accept-Ranges": [
"bytes"
],
"Set-Cookie": [
"firstcookie=want; path=/",
"2cookie=want; path=/",
"cookie3=want; path=/"
],
"Content-Length": [
"6"
],
"Connection": [
"close"
]
}
-- / 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.htmlReceived on 2022-03-18