Is ETag returned in a 304 response?
Asked Answered
P

1

8

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.

Physiography answered 21/1, 2016 at 7:37 Comment(0)
L
14

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.

Lory answered 22/1, 2016 at 12:5 Comment(3)
What about the newer RFCs? Is it mentioned in them at all?Fugere
Found it in tools.ietf.org/html/rfc7232#section-4.1 The server generating a 304 response MUST generate any of the following header fields that would have been sent in a 200 (OK) response to the same request: Cache-Control, Content-Location, Date, ETag, Expires, and Vary.Fugere
Still true in the latest spec, rfc9110, section on 304.Theola

© 2022 - 2024 — McMap. All rights reserved.