-
Notifications
You must be signed in to change notification settings - Fork 515
Description
swapi.co doesn't return 304 (Not Modified) on subsequent requests with If-None-Match request header set to the same value as ETag from the server response
Steps to reproduce (Chrome)
Make sure that cache is not disabled in dev tools. Request the following url twice directly from the browser: http://swapi.co/api/?format=json, or execute fetch('http://swapi.co/api/?format=json') from console.
The first response from the server would have ETag header like this:
Etag:W/"1f7a4766c9ebf66cdb1ddb85d5cc6f2f"
The second request to the server would have If-None-Match header with the same checksum:
If-None-Match:W/"1f7a4766c9ebf66cdb1ddb85d5cc6f2f"
It is expected that the second response would have status code 304 (Not Modified) with empty body, since the checksum hasn't changed. But the actual status code is 200 with the same body as the first request's.
Dev environment
The thing is, it works as expected in dev environment, given that it's being served over HTTP/1.1.
Possible reasons
The first notable difference between prod and dev is that prod responds with weak ETag in the form W/"<string>". It might have something to do with cloudflare, since they support ETag. I haven't investigated that further though.
That I am sure about is that it has to do with weak ETags. Try to make the second request, mentioned above, through curl:
curl -I 'http://swapi.co/api/?format=json' -H 'Origin: null' \
-H 'If-None-Match: W/"1f7a4766c9ebf66cdb1ddb85d5cc6f2f"'
outputs
HTTP/1.1 200 OK
...
Then try to manually remove W/ part from the checksum:
curl -I 'http://swapi.co/api/?format=json' -H 'Origin: null' \
-H 'If-None-Match: "1f7a4766c9ebf66cdb1ddb85d5cc6f2f"'
outputs
HTTP/1.1 304 NOT MODIFIED
...
It would be nice to have it working!

