Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the HTTP 'HEAD' verb useful in web development?

Tags:

http

httpverbs

I've read the w3.org spec on the 'HEAD' verb, and I guess I'm missing something. I can't see how it would be useful.

Is the HTTP 'HEAD' verb useful in web development?

If so, how?

like image 880
Dan Esparza Avatar asked Sep 22 '09 18:09

Dan Esparza


People also ask

When should you use the HTTP HEAD method?

The HEAD method is used to ask only for information about a document, not for the document itself. HEAD is much faster than GET, as a much smaller amount of data is transferred. It's often used by clients who use caching, to see if the document has changed since it was last accessed.

What are HTTP verbs used for?

HTTP verbs tell the server what to do with the data identified by the URL. The HTTP method is supplied in the request line and specifies the operation that the client has requested. HTTP verbs tell the server what to do with the data identified by the URL.

Is head a valid HTTP method?

According to the design of the HTTP specification, GET (along with HEAD) requests are used only to read data and not change it. Therefore, when used this way, they are considered safe.

What is an HTTP head?

HTTP headers are the name or value pairs that are displayed in the request and response messages of message headers for Hypertext Transfer Protocol (HTTP). Usually, the header name and the value are separated by a single colon. HTTP headers are an integral part of HTTP requests and responses.


1 Answers

From RFC2616:

This method (HEAD) can be used for obtaining metainformation about the entity implied by the request without transferring the entity-body itself. This method is often used for testing hypertext links for validity, accessibility, and recent modification.

The reason why HEAD is preferred to GET is due to the absence of the message body in the response making it using in scenarios where you want to determine if the content has changed at all - a change in the last modified time or content length usually signifies this.

Also, a HEAD request will provide some information about the server setup (whether it is IIS/Apache etc.), unless the server was masked; of course, this is available in all responses, but HEAD is preferred especially when you don't know the size of the response. HEAD is also the easiest way to determine if a site is up or down; again the irrelevance of the message body makes HEAD the ideal candidate.

I'm not sure about this, but RSS/ATOM feed readers would use HEAD over GET to ascertain if the contents of the feed have changed.

like image 108
Vineet Reynolds Avatar answered Sep 19 '22 13:09

Vineet Reynolds