I ran into this with Safari 8.0. Despite providing the Last-Modified
header to Safari it would not provide the If-Modified-Since
header on subsequent requests. The fix in my case was to additionally set the Expires
header to the same html-date as the Last-Modified
header.
Here's an example of what the successful exchange looks like:
Initial Request
Standard first request from Safari.
GET http://localhost/image
Host: localhost
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.104 Safari/537.36
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Initial Response
I specify both the Expires
and Last-Modified
headers as the same valid html-date. I have not tried but I doubt Safari will honor an Expires
header set to -1
.
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Expires: Thu, 17 Jul 2014 19:50:58 GMT
Last-Modified: Thu, 17 Jul 2014 19:50:58 GMT
Content-Type: image/png
Content-Length: 1143902
Date: Wed, 22 Oct 2014 15:33:40 GMT
<<DATA>>
Subsequent Request
At last Safari provides the needed If-Modified-Since
header.
GET http://localhost/image
Host: localhost
Connection: keep-alive
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.104 Safari/537.36
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
If-Modified-Since: Thu, 17 Jul 2014 19:50:58 GMT
Subsequent Response
I can satisfyingly return a 304.
HTTP/1.1 304 Not Modified
Server: Apache-Coyote/1.1
Expires: Thu, 17 Jul 2014 19:50:58 GMT
Last-Modified: Thu, 17 Jul 2014 19:50:58 GMT
Date: Wed, 22 Oct 2014 15:33:43 GMT