34

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?

4 Answers 4

34

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

3
  • My first though was just "concurrency control". Good catch about the range requests!
    – rix0rrr
    Jun 21, 2009 at 12:41
  • It's more suitable for concurrency control. I don't know why this answer has so high vote but Range header is more suitable for range requests. e.g. Range: bytes=1024-
    – yakya
    Mar 3, 2016 at 13:47
  • @sotn The OP asked for "practical use of If-Unmodified-Since in the wild", so I didn't give a concept as an answer but 2.5 examples of concurrency control. But maybe you're right; will add another small paragraph.
    – VolkerK
    Mar 3, 2016 at 18:06
9

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.

3

It's useful when resuming large downloads.

-4

Say you are developing an application that shows local weather for a given place. If the server only updates the weather info only 'x' times a day, the browser can take care not to make a http request within that time frame (even if there is a refresh).

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.