Always Geeky

Knowledge base for various geeky topics
 

+menu-

curl with multiple HTTP headers

If you need to set multiple HTTP headers when using curl, you cannot do so by delimiting them with a CRLF or similar line break. Doing so won’t work. You must set each header within a distinct -H parameter.

The correct method:

$ curl -I https://alwaysgeeky.com -H "Host:alwaysgeeky.com" -H "cache-control:no-cache"

Results:
HTTP/1.1 200 OK
Server: cloudflare-nginx
Date: Wed, 17 Oct 2012 20:21:01 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Pingback: https://alwaysgeeky.com/xmlrpc.php
Link: ; rel=shortlink
Vary: Accept-Encoding

Incorrect method:

$ curl -I https://alwaysgeeky.com -H "Host:alwaysgeeky.com\n\rcache-control:no-cache"

Results:
HTTP/1.1 409 Conflict
Server: cloudflare-nginx
Date: Wed, 17 Oct 2012 20:21:41 GMT
Content-Type: text/html
Connection: keep-alive
Cache-Control: max-age=6
Expires: Wed, 17 Oct 2012 20:21:47 GMT

Note that incorrect usage of the -H parameter will not result in 409 error every time. Each webserver, and webserver configuration, will respond to this type of invalid HTTP headers differently.

This entry was posted in Linux and tagged , , . Bookmark the permalink.

 

Leave a Reply