Sending a HTTP request that tells server to return only headers and no body?

kingmaple picture kingmaple · Aug 1, 2012 · Viewed 9.5k times · Source

Are there headers you can send with a HTTP request that tell the web server to send you only headers in response and no body content?

I am using cURL to make such requests, but technically I assume it should be possible with simple header being sent as part of the request.

For example, there exists a 304 Not Modified HTTP Response Code. When you make a request to the server with your cache tag or datetime information, then the server can detect that and only return headers as a response that tell the user agent to use their cache as the response. This means that the response from the server is very, very small when it comes to bandwidth.

But is there a header you can send to servers that make the server only return a header and no body content?

The idea here is to make HTTP requests that otherwise might return large amount of data, very small. Such as an API call that would return JSON data or a log, when in fact the only thing user agent is interested in is making sure that the request went through and nothing else. This is in order to minimize the bandwidth to and from the server in cases where the body might exist, but is not necessary in any way in context to what the user agent is doing.

While it would be possible to design an API that listens to a specific custom header or whatnot, I'd rather not go this way unless I have to. But I've been unable to find if there is a standardized way to make a HTTP request that tells server not to send any body content?

Answer

Ikke picture Ikke · Aug 1, 2012

If the server supports it, there is the HEAD action (as opposed to GET or POST). That tells the server to only send the headers, and no body.

The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response.