HEAD request method
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
TheHEAD HTTP method requests the metadata of a resource in the form ofheaders that the server would have sent if theGET method was used instead.This method can be used in cases where a URL might produce a large download, for example, aHEAD request can read theContent-Length header to check the file size before downloading the file with aGET.
If the response to aHEAD request shows that a cached URL response is now outdated, the cached copy is invalidated even if noGET request was made.
Warning:If a response to aHEAD request has a body, the response body must be ignored.Anyrepresentation headers that describe the erroneous body are assumed to describe the response body that aGET request would have received.
| Request has body | No |
|---|---|
| Successful response has body | No |
| Safe | Yes |
| Idempotent | Yes |
| Cacheable | Yes |
| Allowed inHTML forms | No |
In this article
Syntax
HEAD <request-target>["?"<query>] HTTP/1.1<request-target>Identifies the target resource of the request when combined with the information provided in the
Hostheader.This is an absolute path (e.g.,/path/to/file.html) in requests to an origin server, and an absolute URL in requests to proxies (e.g.,http://www.example.com/path/to/file.html).<query>OptionalAn optional query component preceded by a question-mark
?.Often used to carry identifying information in the form ofkey=valuepairs.
Examples
>Successfully retrieving resource metadata
The followingcurl command creates aHEAD request forexample.com:
curl --head example.comThis is the equivalent to aGET request, except the server shouldn't include a message body in the response.It creates an HTTP request that looks like this:
HEAD / HTTP/1.1Host: example.comUser-Agent: curl/8.6.0Accept: */*The server sends back a200 OK response comprised only of headers.The response is effectively metadata that describes the resource instead of the resource itself (somecaching headers are omitted in this example for brevity):
HTTP/1.1 200 OKContent-Type: text/html; charset=UTF-8Date: Wed, 04 Sep 2024 10:33:11 GMTContent-Length: 1234567Specifications
| Specification |
|---|
| HTTP Semantics> # HEAD> |