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?
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.
If so, the server returns an HTTP status 304 code, letting the client know it can reuse its cached copy.
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.
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.
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
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With