Checking the real HTTP headers with curl
curl, the seminal swiss army knife of HTTP requests, is quite good at many things. Practically everybody knows that you can show headers using the -I flag:
$curl -I http://example.com/req
However, this is plain wrong in a subtle way. See, I sends a HEAD
request, which is sometimes used to probe the server for the last
modification date and such. However, most of the time you want to check
a real GET as opposed to a HEAD. Also, not all web frameworks will automatically implement a HEAD responder for you in addition to a GET responder. It’s also downright misleading because with quite a few proxies the headers you are going to be getting from the server will be different for a GET as opposed to a HEAD.
To perform a “real” GET, hit curl with a lowercase i as opposed to upprecase.
$curl -i http://logik-matchbook.org/shader/Colourmatrix.png
However, this will pollute your terminal with horrible binary-encoded strings (which is normal for a PNG after all)… There are ways to do a full GET and only show a header, the easiest being doing this:
$curl -s -D - http://logik-matchbook.org/shader/Colourmatrix.png -o /dev/null
Works a treat but is long and not memorizable. I put it in my .profile as headercheck:
alias headercheck='curl -s -D - $1 -o /dev/null'
So anytime you want to check headers with a real GET request, hit:
$headercheck http://url.that/you-want-to-check
and you are off to the races.