[kwlug-disc] Utility to parse HTTP response

Khalid Baheyeldin kb at 2bits.com
Fri Jan 31 17:43:33 EST 2025


On Fri, Jan 31, 2025 at 10:49 AM Anton Avramov via kwlug-disc <
kwlug-disc at kwlug.org> wrote:

> P.S. looking for the --write-out switch in the manual I see it has:
> json           A JSON object with all available keys. (Added in 7.70.0)
> So it would be possible to use that and then jq again.
>

I used the --write-out switch to make a small shell script that would
tell me quickly how fast a site is, and whether it redirects

curl -skL -o /dev/null -w
"%{http_code},%{time_total},%{num_redirects},%{url_effective}\n"
www.kwlug.org
200,0.370061,2,https://kwlug.org/

This says that there were 2 redirects, the end HTTP code is 200 (good), and
it took 0.37 seconds to serve the request.

In your case, you can do something like this:

curl -skL -o /dev/null -w "%{http_code}\n%{header_json}\n" www.kwlug.org
200
{
"date":["Thu, 30 Jan 2025 19:00:12 GMT"],
"server":["Apache"],
"cache-control":["max-age=86400, public"],
"x-drupal-dynamic-cache":["MISS"],
"content-language":["en"],
"x-content-type-options":["nosniff"],
"x-frame-options":["SAMEORIGIN"],
"expires":["Sun, 19 Nov 1978 05:00:00 GMT"],
"vary":["Cookie,Accept-Encoding"],
"x-generator":["Drupal 10 (https://www.drupal.org)"],
"x-drupal-cache":["HIT"],
"last-modified":["Thu, 30 Jan 2025 19:00:09 GMT"],
"etag":["\"1738263609\""],
"transfer-encoding":["chunked"],
"content-type":["text/html; charset=UTF-8"]
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kwlug.org/pipermail/kwlug-disc_kwlug.org/attachments/20250131/fb5adc1a/attachment.htm>


More information about the kwlug-disc mailing list