The If-Match
HTTP request header makes the request conditional. For GET
and HEAD
methods, the server will send back the requested resource only if it matches one of the listed ETags
. For PUT
and other non-safe methods, it will only upload the resource in this case.
The comparison with the stored 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:
GET
and HEAD
methods, used in combination with an 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 416
(Range Not Satisfiable) response is returned.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 412
(Precondition Failed) response is returned.Header type | Request header |
---|---|
Forbidden header name | no |
If-Match: <etag_value> If-Match: <etag_value>, <etag_value>, …
"675af34563dc-tr34"
) and may be prefixed by W/
to indicate that the weak comparison algorithm should be used.*
If-Match: "bfc13a64729c4290ef5b2c2730249c88ca92d82d" If-Match: W/"67ab43", "54ed21", "7892dd" If-Match: *
Specification | Title |
---|---|
RFC 7232, section 3.1: If-Match | Hypertext Transfer Protocol (HTTP/1.1): Conditional Requests |
Feature | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | Yes | Yes | Yes | Yes | Yes | Yes |
Feature | Android webview | Chrome for Android | Edge mobile | Firefox for Android | IE mobile | Opera Android | iOS Safari |
---|---|---|---|---|---|---|---|
Basic support | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
ETag
If-Unmodified-Since
If-Modified-Since
If-None-Match
416
Range Not Satisfiable
412
Precondition Failed
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Match