diff --git a/docs/cmdline-opts/write-out.d b/docs/cmdline-opts/write-out.d index df926a0490..208b302c91 100644 --- a/docs/cmdline-opts/write-out.d +++ b/docs/cmdline-opts/write-out.d @@ -22,10 +22,11 @@ output a newline by using \\n, a carriage return with \\r and a tab space with The output will be written to standard output, but this can be switched to standard error by using %{stderr}. -Output HTTP headers from the most recent request by using \fB%header{name}\fP -where \fBname\fP is the case insensitive name of the header (without the -trailing colon). The header contents are exactly as sent over the network, -with leading and trailing whitespace trimmed. Added in curl 7.83.0. +EXPERIMENTAL feature: Output HTTP headers from the most recent request by +using \fB%header{name}\fP where \fBname\fP is the case insensitive name of the +header (without the trailing colon). The header contents are exactly as sent +over the network, with leading and trailing whitespace trimmed. Added in curl +7.83.0. .B NOTE: The %-symbol is a special symbol in the win32-environment, where all @@ -54,7 +55,16 @@ The initial path curl ended up in when logging on to the remote FTP server. (Added in 7.15.4) .TP .B header_json -A JSON object with all HTTP response headers from the recent transfer. +EXPERIMENTAL feature. + +A JSON object with all HTTP response headers from the recent transfer. Values +are provided as arrays, since in the case of multiple headers there can be +multiple values. + +The header names are listed in order of appearance over the wire using the +same case as was used over the network. Except for duplicated headers. They +are grouped on the first occurance of that header, using the casing of the +first header, and then each value is presented in the JSON array. .TP .B http_code The numerical response code that was found in the last retrieved HTTP(S) or diff --git a/tests/data/Makefile.inc b/tests/data/Makefile.inc index 200e6af51c..9863a9d21c 100644 --- a/tests/data/Makefile.inc +++ b/tests/data/Makefile.inc @@ -209,7 +209,7 @@ test1630 test1631 test1632 test1633 test1634 \ test1650 test1651 test1652 test1653 test1654 test1655 \ test1660 test1661 \ \ -test1670 \ +test1670 test1671 \ \ test1680 test1681 test1682 test1683 \ \ diff --git a/tests/data/test1671 b/tests/data/test1671 new file mode 100644 index 0000000000..ed4169955f --- /dev/null +++ b/tests/data/test1671 @@ -0,0 +1,70 @@ + + + +HTTP +HTTP GET +-w +%header + + + +# +# Server-side + + +HTTP/1.1 200 OK +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=/ +Funny-head: yesyes +Set-Cookie: 2cookie=want2; path=/ +Content-Type: text/html +Set-Cookie: cookie3=want3; path=/ +Content-Length: 6 +Connection: close + +-foo- + + + +# +# Client-side + + +http + + +-w header JSON output + + +http://%HOSTIP:%HTTPPORT/%TESTNUMBER -w '%{header_json}\n' -o log/%TESTNUMBER.out + + + +# +# Verify data after the test has been "shot" + + +GET /%TESTNUMBER HTTP/1.1 +Host: %HOSTIP:%HTTPPORT +User-Agent: curl/%VERSION +Accept: */* + + + +{"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"] +} + + + +o \ No newline at end of file