Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the use of If-Unmodified-Since HTTP Header?

Tags:

http

Do you know of any practical use of If-Unmodified-Since in the wild? From the description, it appears that this header was meant to help with avoiding dirty writes. i.e. update this resource only if it hasn't been modified since the last-modified-time available with client. Unlike If-Modified-Since, it doesn't seem to help with caching. Am I missing something?

like image 366
ottodidakt Avatar asked Jun 21 '09 10:06

ottodidakt


People also ask

What is the purpose for the if-modified-since header?

The If-Modified-Since HTTP header indicates the time for which a browser first downloaded a resource from the server. This helps determine whether or not the resource has changed since the last time it was accessed.

What is the purpose of if-modified-since?

The If-Modified-Since request HTTP header makes the request conditional: the server sends back the requested resource, with a 200 status, only if it has been last modified after the given date.

What are the If-modified-since and if none match header used for?

The If-Modified-Since header is used to specify the time at which the browser last received the requested resource. The If-None-Match header is used to specify the entity tag that the server issued with the requested resource when it was last received.

What is an IF Match header?

The If-Match HTTP request header makes a request conditional. A server will only return requested resources for GET and HEAD methods, or upload resource for PUT and other non-safe methods, if the resource matches one of the listed ETag values.


2 Answers

You can use it e.g. for a range request.
example: your client requests the resource http://examp.le/foo?id=3 and the Contents-length is 4096 but your client only requests the first 1024 bytes. It can then (at a later time) request the remaining 3072 bytes but that doesn't make sense if the resource has changed meanwhile.

edit: Also you might not want to change/update data if the resource has changed meanwhile. E.g. you request a customer record and edit something. If someone else has changed the record in the meantime this might lead to inconsistencies. Therefore send your updates with an if-unmodified-since(-I-retrieved-the-data) header and the webserver will/should reject your updates if the record has already been changed - your client can then request the "conflicting" data.

edit2: since you've asked for "any practical use of If-Unmodified-Since in the wild": see http://msdn.microsoft.com/en-us/library/dd179371.aspx#Subheading1.
Let's assume you've first requested the Blob properties. Now you know e.g. the Content-type and Content-length (maybe you need this for some kind of allocation). Someone/something might change the blob before you send the second, Get Blob request. If you send the value of Last-Modified as value of the If-Unmodified-Since header the server will respond with the appropriate error code if the blob has changed.


Those are examples of an optimistic lock/stamped lock as a means of concurrency control, where the value of the Last-Modified header serves as the guard token. See e.g. https://en.wikipedia.org/wiki/Optimistic_concurrency_control
like image 111
VolkerK Avatar answered Sep 19 '22 21:09

VolkerK


It's useful for multiple requests, conducted over a period of time, but relating to a single unchanged resource.

Examples:

  • Range requests. The response to the first range request (or perhaps a preliminary HEAD) includes the Last-Modified header. Subsequent requests are meant for the same version of that resource only. If the resource changed between the time we started the sequence of range requests and some time in the middle of the sequence, we want to start over.

  • Optimistic concurrency control. We first GET a resource, make some changes client-side, and wish to PUT the updated resource. But we only want to PUT the updated resource so long as nobody else updated it in the meantime. We don't want to overwrite anybody's changes. If it turns out somebody has changed the resource in the meantime, we want to GET it again, attempt to re-apply the changes in the client (sort of like git rebase), and try to PUT the changed resource again.

like image 27
yfeldblum Avatar answered Sep 19 '22 21:09

yfeldblum