Quick Tip: Viewing Headers With Curl

Something that I do often at work is to check HTTP headers for random things such as redirects, cache headers, proxies, ssl, etc.

A common way this is done is by using the -I (--header) switch:

$ curl -I http://example.com/
HTTP/1.1 200 OK
Content-Encoding: gzip
Accept-Ranges: bytes
Cache-Control: max-age=604800
Content-Type: text/html
Date: Wed, 27 Jun 2018 22:03:57 GMT
Etag: "1541025663+gzip"
Expires: Wed, 04 Jul 2018 22:03:57 GMT
Last-Modified: Fri, 09 Aug 2013 23:54:35 GMT
Server: ECS (atl/FC94)
X-Cache: HIT
Content-Length: 606
Code language: JavaScript (javascript)

The downside to this is that it uses an HTTP HEAD request, which can sometimes return different headers or different information than a standard GET request. This can be fixed by using the -X (--request) switch. This overrides the default HEAD?request with whatever you choose:

$ curl -I -XGET http://example.com/
HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: max-age=604800
Content-Type: text/html
Date: Wed, 27 Jun 2018 22:07:47 GMT
Etag: "1541025663"
Expires: Wed, 04 Jul 2018 22:07:47 GMT
Last-Modified: Fri, 09 Aug 2013 23:54:35 GMT
Server: ECS (atl/FC90)
Vary: Accept-Encoding
X-Cache: HIT
Content-Length: 1270
Code language: JavaScript (javascript)

I like to just combine them into one quick command: curl -IXGET http://example.com/

Other Posts Not Worth Reading

Hey, You!

Like this kind of garbage? Subscribe for more! I post like once a month or so, unless I found something interesting to write about.


Comments

Leave a Reply