HTTP HEAD Request Method

The HTTP HEAD method requests HTTP headers from the server as if the document was requested using the HTTP GET method. The only difference between HTTP HEAD and GET requests is that for HTTP HEAD, the server only returns headers without body.

The HTTP HEAD method is much faster than the HTTP GET method because much less data is transferred in HEAD requests. Browsers use the HEAD method to update information about cached resources to check if the resource has been modified since the last time it was accessed. If the resource has not been modified, browsers reuse the local copy without issuing a new request. Otherwise, they request an updated version of the resource with a GET request.

The meta-information returned in the HTTP headers for a HEAD request must be identical to the meta-information returned for a GET request. The HTTP HEAD request is often used to retrieve meta-information about a resource at a specified URI without transmitting actual data. For example, to check the availability of hypertext links (check for broken links).

Requests using the HTTP HEAD method should only retrieve data (server must not change its state). If you want to change data on the server, use POST, PUT, PATCH or DELETE methods. The HTTP HEAD method is defined as idempotent, which means that multiple identical HEAD requests should have the same effect as a single request.

What is the difference between the HTTP HEAD and GET methods?

The HTTP HEAD and GET methods are identical, except that for HEAD requests, the server does not return a response body but still specifies the size of the response content using the Content-Length header.

HTTP HEAD Request Example

The following HTTP HEAD request example demonstrates sending a HEAD request to the server.

HTTP HEAD Request Example Run Example
HEAD /echo/head/json HTTP/1.1
Accept: application/json

And the server response:

Server Response to HTTP HEAD Request
HTTP/1.1 200 OK
Content-Length: 19
Content-Type: application/json

What is the HTTP HEAD request method used for?

The HTTP HEAD request is used to check the availability, size, and last modification date of a resource without downloading it (as indicated by the Content-Length and Last-Modified headers).

For example, we can send a GET request to check if a PDF file is available for download. The server will return a 200 status code if the file is available and a 404 status code if the file is no longer available. The server will also return the PDF file contents in the response body. If the PDF file size is several megabytes, then we will get unnecessary traffic of several megabytes. In the case of a HEAD request, we will still get the 200 and 404 status codes, but without the extra few megabytes of traffic.

Can I send data using the HTTP HEAD method?

No, HTTP HEAD requests cannot have a message body. But you still can send data to the server using the URL parameters. In this case, you are limited to the maximum size of the URL, which is about 2000 characters (it depends on the browser).

Can I send HTTP Headers using the HEAD method?

Yes, you can send any HTTP headers along with the HEAD request, just like you would for a GET request. For example, you can send user authentication data in the Authorization header, or provide additional information about your server with the X-Powered-By header, or about your user with the X-User-IP header. By default, browsers send the Accept, Accept-Encoding, User-Agent, and Referer HTTP headers on every HEAD and GET request.

Some notes on HTTP HEAD requests

  • HEAD requests can be cached
  • HEAD requests should never be used when dealing with sensitive data

See also

Last updated: Viewed: 7145 times