🎉 Requestly joins BrowserStack to build the future of application testing. Read more

HTTP Headers

If Match

HTTP Header

The HTTP If-Match request header allows a request to be made conditionally.
A server will respond with the resources for GET and HEAD methods, or upload resources for PUT and other non-safe methods, only if the resource’s current ETag matches one of the values specified in the If-Match header.
If the condition is not met, the server will return a 412 Precondition Failed response instead.

The matching process involves a robust comparison with the stored ETag, using a strong comparison algorithm which considers two files identical only if they are byte-for-byte identical.
If an ETag has a W/ prefix indicating a weak entity tag, this comparison will not match it.

Two primary use cases are:

  • For GET and HEAD methods, especially when used with a Range header, it ensures that the requested ranges originate from the same resource as the previous request.
  • For other HTTP methods, particularly PUT, If-Match helps prevent the lost update problem.
    It verifies that the modification of a resource does not override changes made by others since the resource was last fetched.

Syntax

http
If-Match: <etag_value>
If-Match: <etag_value>, <etag_value>, …

Directives

<etag_value>

Entity tags uniquely representing the requested resources. They are strings of ASCII characters enclosed in double quotes, such as "675af34563dc-tr34". These tags can be prefixed with W/ to indicate they are ‘weak’, meaning they represent the resource semantically but not byte-for-byte. In an If-Match header, weak entity tags will not match.

*

The asterisk (*) signifies any resource. Note that this does not match if the server has no current representation of the target resource.

Example

Here are some example HTTP headers for the “If-Match” condition:

What does “If-Match” do? It makes the request conditional: the server will only proceed if the entity matches the provided ETag values. This is useful for managing concurrent data updates or ensuring data integrity.

Examples include:

It can contain a specific ETag, such as:

If-Match: “bfc13a64729c4290ef5b2c2730249c88ca92d82d”

Multiple ETags can be specified, separated by commas:

If-Match: “67ab43”, “54ed21”, “7892dd”

And it can also use the wildcard “*” to match any entity:

If-Match: *

How to Modify Header using Requestly

Requestly is a powerful Chrome extension that allows you to modify HTTP headers, including the If-Match header. This is particularly helpful when you want to test how your server handles conditional requests based on entity tags (ETags) during development or troubleshooting. Steps to Modify the If-Match Header:

  1. Install and open the Requestly Chrome extension. You can find it on the Chrome Web Store.
  2. Create a new rule: Click on “Create Rule” and choose “Modify Headers” from the list of available rule types.
  3. Add a new header modification:
    • Under “Action”, select “Add” or “Override”.
    • In the “Header Name” field, enter If-Match.
    • In the “Header Value” field, enter the desired ETag value (e.g., “123abc”).
  4. Set the URL condition: Specify the URL or pattern where this header change should apply (e.g., https://your-api.com/*).
  5. Save the rule.

Once set up, Requestly will inject the If-Match: “123abc” header into all matching requests, allowing you to test how your server processes conditional updates and handles concurrency control.

You might need to modify the If-Match header to simulate update requests that depend on specific resource versions, helping you ensure correct behavior when handling data conflicts or concurrent changes.