Search code examples
httphttp-status-codeshttp-status-code-304

Is ETag returned in a 304 response?


I'm building a node.js app which - reguarly, once a day - fetches data from some external web server (using "request" package).

I want to avoid fetching same data twice, so I keep track of each resource ETag when first downloading (200 status code).

Then, when fetching again (next day) that resource I add an If-None-Match header with the saved etag in the request.

Since I suspect to sometime receive a 200 status code (instead of expected 304) from the remote web server even if a resource contents is not modified, I ask if I should expect the resource ETag to be returned in a 304 response (and how to get it in the request response...), to try to debug this issue.


Solution

  • Please have a look at appropriate RFC 2616.

    The response MUST include the following header fields: (...)

    • ETag and/or Content-Location, if the header would have been sent in a 200 response to the same request

    So if ETag header is returned with 200 OK status code it also must be included in 304 Not Modified response.