cURL HEAD Request

Performing HTTP HEAD requests using cURL from the command line.

4715 views

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:

  1. An in-dept look at the use of headings (h1-h6) and sections in HTML pages.
  2. Pagination can be a confusing thing to get right both practically and programmatically. I have put a lot of thought into this subject, and here I am giving you a few of the ideas I have been working with.
  3. The best way to deal with a trailing question mark is probably just to make it a bad request, because it is a very odd thing to find in a request URL.
  4. How to optimize image-loading and automatically include width and height attributes on img elements with PHP.
  5. HTTP headers are not case-sensitive, so we are free to convert them to all-lowercase in our applications.

More in: Web development