Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What if both If-Modified-Since and If-None-Match are present in HTTP headers

I've been reading RFC 2616 - sec14.26 and RFC 2616 - sec13.3.3 for quite a long time, but I'm still not sure if I understand correctly.

The section 14.26 states that

If any of the entity tags match the entity tag of the entity that would have been returned in the response to a similar GET request (without the If-None-Match header) on that resource, or if "*" is given and any current entity exists for that resource, then the server MUST NOT perform the requested method, unless required to do so because the resource's modification date fails to match that supplied in an If-Modified-Since header field in the request. Instead, if the request method was GET or HEAD, the server SHOULD respond with a 304 (Not Modified) response, including the cache- related header fields (particularly ETag) of one of the entities that matched.

,

If none of the entity tags match, then the server MAY perform the requested method as if the If-None-Match header field did not exist, but MUST also ignore any If-Modified-Since header field(s) in the request. That is, if no entity tags match, then the server MUST NOT return a 304 (Not Modified) response.

and the section 13.3.3 states that

An HTTP/1.1 origin server, upon receiving a conditional request that includes both a Last-Modified date (e.g., in an If-Modified-Since or If-Unmodified-Since header field) and one or more entity tags (e.g., in an If-Match, If-None-Match, or If-Range header field) as cache validators, MUST NOT return a response status of 304 (Not Modified) unless doing so is consistent with all of the conditional header fields in the request.

I'm quite confused whether a unconditionally compliant HTTP server should response to a client request (GET / HEAD) where

  1. the condition If-Modified-Since matches, but If-None-Match doesn't.
  2. or, the condition If-None-Match matches, but If-Modified-Since doesn't.

According to the section 14.26, 304 Not Modified should be returned in the first case and 200 OK in the second case since If-Modified-Since is ignored.

But the section 13.3.3 says that "it MUST NOT return a response status of 304 (Not Modified) unless doing so is consistent with all of the conditional header fields in the request.", meaning that 200 OK should be returned in the both cases.

like image 474
Wenhao Ji Avatar asked Aug 15 '14 06:08

Wenhao Ji


1 Answers

from RFC 7232

A recipient must ignore If-Modified-Since if the request contains an If-None-Match header field; the condition in If-None-Match is considered to be a more accurate replacement for the condition in If-Modified-Since, and the two are only combined for the sake of interoperating with older intermediaries that might not implement If-None-Match.

like image 108
SKing7 Avatar answered Sep 18 '22 00:09

SKing7