javaBin / ems-redux

Baksystemet som holder på alle foredrag som er sendt inn til JavaZone gjennom historien.
Apache License 2.0
10 stars 4 forks source link

If-Modified-Since and Last-Modified for binaries (speaker images) #20

Closed chrissearle closed 7 years ago

chrissearle commented 10 years ago

We're updating the iOS app to prevent it downloading speaker images every time you open a session.

To do so we're now sending the If-Modified-Since header.

This is working fine for gravatar images (48 speakers in 2014) but not for EMS images (111 speakers in 2014).

Nor does EMS send the Last-Modified header - so I have no date to check against.

Oddly - EMS seems to respect If-Modified-Since for non-images - but for images it just returns a 200 OK and the image instead of 304 Not Modified.

Some sample URLS.

Relates to https://github.com/javaBin/ems-ios/issues/129

chrissearle commented 9 years ago

Something odd.

Let's say I already have an image - and it has a last modified of Wed, 18 Jun 2014 10:19:39 GMT

Then I request again - this time with If-Modified-Since

GET /ems/server/binary/fb08ed18-e50c-4518-af87-bf699dcc7024?size=thumb HTTP/1.1
Host: javazone.no
Accept: */*
If-Modified-Since: Wed, 18 Jun 2014 10:19:39 GMT
User-Agent: JavaZone/22 CFNetwork/711.1.12 Darwin/14.1.0
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Connection: keep-alive

Then what I expect is 304 Not Modified - but what I get is:

HTTP/1.1 200 OK
Server: nginx/1.1.19
Date: Wed, 04 Mar 2015 09:45:56 GMT
Content-Disposition: attachment; filename="cv-bilde-wendel.jpg"
Content-Length: 13627
Content-Type: image/jpeg
Last-Modified: Wed, 18 Jun 2014 10:19:39 GMT
Via: 1.1 aer01-mda1-dmz-wsa-1.cisco.com:80 (Cisco-WSA/8.5.0-497), 1.1 Application and Content Networking System Software 5.5.31
Connection: Close

So - the last modified info is there - but it's not actually giving the correct response for the request with if-modified-since set?

hamnis commented 9 years ago

The behaviour is correct.

https://tools.ietf.org/html/rfc7232#section-3.4

or even

https://tools.ietf.org/html/rfc7232#section-3

hamnis commented 9 years ago
$ curl "http://javazone.no/ems/server/binary/fb08ed18-e50c-4518-af87-bf699dcc7024?size=thumb" -v > /dev/null
* Hostname was NOT found in DNS cache
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 212.71.237.26...
* Connected to javazone.no (212.71.237.26) port 80 (#0)
> GET /ems/server/binary/fb08ed18-e50c-4518-af87-bf699dcc7024?size=thumb HTTP/1.1
> User-Agent: curl/7.37.1
> Host: javazone.no
> Accept: */*
>
< HTTP/1.1 200 OK
* Server nginx/1.1.19 is not blacklisted
< Server: nginx/1.1.19
< Date: Wed, 04 Mar 2015 14:15:57 GMT
< Content-Type: image/jpeg
< Content-Length: 13627
< Connection: keep-alive
< Last-Modified: Wed, 18 Jun 2014 10:19:39 GMT
< Content-Disposition: attachment; filename="cv-bilde-wendel.jpg"
<
{ [data not shown]
100 13627  100 13627    0     0   155k      0 --:--:-- --:--:-- --:--:--  156k
* Connection #0 to host javazone.no left intact
[  3:16PM ]  [ maedhros@arya:~/Projects/schibsted/recsys ]
 $ curl -H 'If-Modified-Since: Wed, 18 Jun 2014 10:19:39 GMT' "http://javazone.no/ems/server/binary/fb08ed18-e50c-4518-af87-bf699dcc7024?size=thumb" -v > /dev/null
* Hostname was NOT found in DNS cache
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 212.71.237.26...
* Connected to javazone.no (212.71.237.26) port 80 (#0)
> GET /ems/server/binary/fb08ed18-e50c-4518-af87-bf699dcc7024?size=thumb HTTP/1.1
> User-Agent: curl/7.37.1
> Host: javazone.no
> Accept: */*
> If-Modified-Since: Wed, 18 Jun 2014 10:19:39 GMT
>
< HTTP/1.1 304 Not Modified
* Server nginx/1.1.19 is not blacklisted
< Server: nginx/1.1.19
< Date: Wed, 04 Mar 2015 14:16:19 GMT
< Connection: keep-alive
<
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
* Connection #0 to host javazone.no left intact
chrissearle commented 9 years ago

OK - weirder than weird.

That output was from wireshark - what it actually observed on the wire - not from the client I was testing.

But - if I use telnet:

~  » telnet javazone.no 80
Trying 212.71.237.26...
Connected to javazone.no.
Escape character is '^]'.
GET /ems/server/binary/fb08ed18-e50c-4518-af87-bf699dcc7024?size=thumb HTTP/1.1
Host: javazone.no
Accept: */*
If-Modified-Since: Wed, 18 Jun 2014 10:19:39 GMT
User-Agent: JavaZone/22 CFNetwork/711.1.12 Darwin/14.1.0
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Connection: keep-alive

HTTP/1.1 304 Not Modified
Server: nginx/1.1.19
Date: Wed, 04 Mar 2015 15:25:45 GMT
Connection: keep-alive

Note that here I copied and pasted the HTTP conversation above into telnet - and bam - a 304.

So now I just don't know what's going on.

henrikno commented 7 years ago

This seems to work for javazone-web-api. Fixed?