Alex Scotton

App & Web Developer

Check HTTP Headers in Linux with cURL

Posted by Alex Scotton on 29/6/2013

I needed to check some RewriteRules in a new .htaccess file and found a good alternative to just adding another Chrome Extension.

cURL is "a command line tool for getting or sending files using URL syntax", which up until recently I had only used for checking APIs and grabbing my current WAN IP:

$ curl

However, it is also capable of outputing a range of information about the HTTP transaction including the response headers. Run the following command to see it in action:

$ curl -s -D - -o /dev/null
HTTP/1.0 302 Found
Server: BigIP
Connection: Keep-Alive
Content-Length: 0

You can also add a useragent to your request to check for mobile redirects:

$ curl -s -D - -A "My own custom useragent string" -o /dev/null

Awesome, huh?

It's a little long for my liking though. So, I wrote a short function to make the command much easier to run. I'm a huge fan of zsh, so I pop the following in the .zshrc file in my home directory:

curlHead() {
    if [ ! $1 ] ; then
        print "Usage: \n$ curlHead url useragent"
        return 1
    elif [ $2 ] ; then
        curl -s -D - $1 -A $2 -o /dev/null
        curl -s -D - $1 -o /dev/null

Now I can run:

$ curlHead "My own custom useragent string"

If you have any expansions on the above, please share in the comments below.

Happy HTTP Debugging.