cURL HEAD Request
Performing HTTP HEAD requests using cURL from the command line.
Edited: 2022-09-29 11:36
curl -X HEAD http://beamtic.com/Examples/ip.php
Result:
HTTP/2 200
date: Sat, 09 Nov 2019 03:43:23 GMT
server: Apache/2.4.29 (Ubuntu)
x-content-type-options: nosniff
x-powered-by: Doorkeeper
etag: 10de3a4430t7b8b1a19f9mdr558qa1d3
content-type: text/html; charset=utf-8
Details
Sending a HTTP HEAD request works similar to sending a GET request. The difference is that the server should only return the response headers of the requested page, leaving the response body empty.
This is useful when determining if a page has been updated, as it avoids downloading the entire body, and saves bandwidth for both the client and the server.
To send a HTTP HEAD request with cURL we can use the --HEAD option:
curl --HEAD http://beamtic.com/Examples/ip.php
Note. "-I" can also be used instead of "--HEAD".
If you want to show verbose information to "make the operation more talkative", which can be useful when learning, use the -verbose or -v option. Doing this will also show information about the TLS handshake.
curl --verbose --HEAD --silent https://beamtic.com/
Note. The -s or --silent option activates "silent mode", which will hide progress bars.
To make the examples more user friendly, I have used the full option names --OPTION_NAME rather than the short versions -O.
Content negotiation
HEAD requests are very useful when you need to verify that your server is delivering the correct response headers. If you want to make sure your server supports Brotli or Gzip, you could just send a forged accept-encoding request header in your curl command; this can be done like so:
curl --HEAD -H "accept-encoding: br" https://beamtic.com/
If you wanted to check for GZIP you would instead do like this:
curl --HEAD -H "accept-encoding: gzip" https://beamtic.com/
If a client supports multiple compressions, it may list them in the order of preference:
accept-encoding: br, gzip
Tell us what you think: