Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 1104721 of If-Match

  • Revision slug: Web/HTTP/Headers/If-Match
  • Revision title: If-Match
  • Revision id: 1104721
  • Created:
  • Creator: teoli
  • Is current revision? No
  • Comment

Revision Content

{{HTTPSidebar}}

The If-Match request HTTP 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.

Comparison with the stored {{HTTPHeader("ETag")}} uses the strong comparison algorithm, meaning two files are considered identical if they identical byte to byte. 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 ones. If it doesn't match then, a {{HTTPStatus("416")}} Range Not Satisfiable is returned.
  • For other methods, and in particular for {{HTTPMethod("PUT")}}, If-Match can be used to prevent the lost update problem, by checking that 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 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 by W/ to indicate that the weak comparison algorithm should be used.

Examples

If-Match: "bfc13a64729c4290ef5b2c2730249c88ca92d82d"

If-Match: W/"67ab43", "54ed21", "7892dd"

Specifications

Specification Title
{{RFC("7232", "If-Match", "3.1")}} Hypertext Transfer Protocol (HTTP/1.1): Conditional Requests

Browser compatibility

{{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

Revision Source

<div>{{HTTPSidebar}}</div>

<p>The <strong><code>If-Match</code></strong> request HTTP 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.</p>

<p>Comparison with the stored {{HTTPHeader("ETag")}} uses the <em>strong comparison algorithm</em>, meaning two files are considered identical if they identical byte to byte. This is weakened when the&nbsp; <code>W/</code> prefix is used in front of the ETag.</p>

<p>There are two common use cases:</p>

<ul>
 <li>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 ones. If it doesn't match then, a {{HTTPStatus("416")}}<code> Range Not Satisfiable</code> is returned.</li>
 <li>For other methods, and in particular for {{HTTPMethod("PUT")}}, <code>If-Match</code> can be used to prevent the <a href="https://www.w3.org/1999/04/Editing/#3.1">lost update problem</a>, by checking that 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")}}<code> Precondition Failed</code> is returned.</li>
</ul>

<table class="properties">
 <tbody>
  <tr>
   <th scope="row">Header type</th>
   <td>{{Glossary("Request header")}}</td>
  </tr>
  <tr>
   <th scope="row">{{Glossary("Forbidden header name")}}</th>
   <td>no</td>
  </tr>
 </tbody>
</table>

<h2 id="Syntax">Syntax</h2>

<pre class="syntaxbox">
If-Match: &lt;etag_value&gt;
If-Match: &lt;etag_value&gt;, &lt;etag_value&gt;, …
</pre>

<h2 id="Directives">Directives</h2>

<dl>
 <dt>&lt;etag_value&gt;</dt>
 <dd>Entity tags uniquely representing the requested resources. They are a string of ASCII characters placed between double quotes (Like <code>"675af34563dc-tr34"</code>) and may be prefixed by <code>W/</code> to indicate that the weak comparison algorithm should be used.</dd>
</dl>

<h2 id="Examples">Examples</h2>

<pre>
If-Match: "bfc13a64729c4290ef5b2c2730249c88ca92d82d"

If-Match: W/"67ab43", "54ed21", "7892dd"
</pre>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Title</th>
  </tr>
  <tr>
   <td>{{RFC("7232", "If-Match", "3.1")}}</td>
   <td>Hypertext Transfer Protocol (HTTP/1.1): Conditional Requests</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<p class="hidden">The compatibility table in this page is generated from structured data. If you’d like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data/README.md">https://github.com/mdn/browser-compat-data/README.md</a> and send us a pull request.</p>

<p>{{Compat}}</p>

<h2 id="See_also">See also</h2>

<ul>
 <li>{{HTTPHeader("ETag")}}</li>
 <li>{{HTTPHeader("If-Unmodified-Since")}}</li>
 <li>{{HTTPHeader("If-Modified-Since")}}</li>
 <li>{{HTTPHeader("If-None-Match")}}</li>
 <li>{{HTTPStatus("416")}}<code> Range Not Satisfiable</code></li>
 <li>{{HTTPStatus("412")}}<code> Precondition Failed</code></li>
</ul>
Revert to this revision