Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP If-Modified-Since with milliseconds

Let's say I get an object from REST web service and this object has a time stamp. This time stamp has a milliseconds component. Next time I request the same object I don't want it to be returned unless it has changed, so I use the If-Modified-Since header. But the date in that header is not even supposed to have milliseconds. If I round the time stamp down, I'll always get the object back as if it's always modified. If I round it up I risk missing some updates. Is the If-Modified-Since header completely useless to me in this case, or am I missing something?

like image 951
Joe Shmo Avatar asked Sep 03 '13 23:09

Joe Shmo


People also ask

What does if-modified-since mean in HTTP?

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 HTTP status code is returned from the server in response to an if-modified-since HTTP GET When the file has not been modified since the specified time?

If so, the server returns an HTTP status 304 code, letting the client know it can reuse its cached copy.

Do you see an if-modified-since line in the HTTP GET?

Now inspect the contents of the second HTTP GET request from your browser to the server. Do you see an “IF-MODIFIED-SINCE:” line in the HTTP GET? If so, what information follows the “IF-MODIFIED-SINCE:” header? Answer: Yes.

What are the If-modified-since and if none match headers 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.


1 Answers

A service that sends a time stamp with milliseconds is not HTTP-compliant. Last-Modified MUST be sent as a HTTP-date which §3.3.1 specifies very clearly:

HTTP-date    = rfc1123-date | rfc850-date | asctime-date
rfc1123-date = wkday "," SP date1 SP time SP "GMT"
rfc850-date  = weekday "," SP date2 SP time SP "GMT"
asctime-date = wkday SP date3 SP time SP 4DIGIT
date1        = 2DIGIT SP month SP 4DIGIT
              ; day month year (e.g., 02 Jun 1982)
date2        = 2DIGIT "-" month "-" 2DIGIT
              ; day-month-year (e.g., 02-Jun-82)
date3        = month SP ( 2DIGIT | ( SP 1DIGIT ))
              ; month day (e.g., Jun  2)
time         = 2DIGIT ":" 2DIGIT ":" 2DIGIT
              ; 00:00:00 - 23:59:59
wkday        = "Mon" | "Tue" | "Wed"
            | "Thu" | "Fri" | "Sat" | "Sun"
weekday      = "Monday" | "Tuesday" | "Wednesday"
            | "Thursday" | "Friday" | "Saturday" | "Sunday"
month        = "Jan" | "Feb" | "Mar" | "Apr"
            | "May" | "Jun" | "Jul" | "Aug"
            | "Sep" | "Oct" | "Nov" | "Dec"

File a bug with the service you are using. It is invalid to send Last-Modified or If-Modified-Since with milliseconds.

If sub-second accuracy is important, it may be more appropriate to use entity tags (ETag).

like image 53
josh3736 Avatar answered Oct 02 '22 02:10

josh3736