The If-Match
HTTP request header makes the request conditional. For {{HTTPMethod("GET")}} and {{HTTPMethod("HEAD")}} methods, the server will send back the requested resource only if it matches one of the listed ETags
. For {{HTTPMethod("PUT")}} and other non-safe methods, it will only upload the methods in this case.
The comparison with the stored {{HTTPHeader("ETag")}} uses the strong comparison algorithm, meaning two files are considered identical byte to byte only. This is weakened when the W/
prefix is used in front of the ETag
.
There are two common use cases:
- For {{HTTPMethod("GET")}} and {{HTTPMethod("HEAD")}} methods, used in combination with an {{HTTPHeader("Range")}} header, it can guarantee that the new ranges requested comes from the same resource than the previous one. If it doesn't match, then a {{HTTPStatus("416")}}
- For other methods, and in particular for {{HTTPMethod("PUT")}},
If-Match
can be used to prevent the lost update problem. It can check if the modification of a resource that the user wants to upload will not override another change that has been done since the original resource was fetched. If the request cannot be fulfilled, the {{HTTPStatus("412")}} (Precondition Failed) response is returned.
Header type | {{Glossary("Request header")}} |
---|---|
{{Glossary("Forbidden header name")}} | no |
Syntax
If-Match: <etag_value> If-Match: <etag_value>, <etag_value>, …
Directives
- <etag_value>
- Entity tags uniquely representing the requested resources. They are a string of ASCII characters placed between double quotes (Like
"675af34563dc-tr34"
) and may be prefixed byW/
to indicate that the weak comparison algorithm should be used. *
- The asterisk is a special value representing any resource.
Examples
If-Match: "bfc13a64729c4290ef5b2c2730249c88ca92d82d" If-Match: W/"67ab43", "54ed21", "7892dd" If-Match: *
Specifications
Specification | Title |
---|---|
{{RFC("7232", "If-Match", "3.1")}} | Hypertext Transfer Protocol (HTTP/1.1): Conditional Requests |
Browser compatibility
The compatibility table in this page is generated from structured data. If you’d like to contribute to the data, please check out https://github.com/mdn/browser-compat-data/README.md and send us a pull request.
{{Compat}}
See also
- {{HTTPHeader("ETag")}}
- {{HTTPHeader("If-Unmodified-Since")}}
- {{HTTPHeader("If-Modified-Since")}}
- {{HTTPHeader("If-None-Match")}}
- {{HTTPStatus("416")}}
Range Not Satisfiable
- {{HTTPStatus("412")}}
Precondition Failed