Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 630
MarcoS Avatar asked Jan 21 '16 07:01

MarcoS


People also ask

What is ETag in HTTP response?

An ETag (entity tag) is an HTTP header that is used to validate that the client (such as a mobile device) has the most recent version of a record. When a GET request is made, the ETag is returned as a response header. The ETag also allows the client to make conditional requests.

What is a 304 response code?

The HTTP 304 Not Modified client redirection response code indicates that there is no need to retransmit the requested resources. It is an implicit redirection to a cached resource.

Does a 304 response generally contain a message body?

The 304 response MUST NOT contain a message-body, and thus is always terminated by the first empty line after the header fields.


1 Answers

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.

like image 91
Opal Avatar answered Nov 15 '22 07:11

Opal