I have a web server which provides an ETag for a particular url. When the browser performs a request for this url, it provides the http-header “If-None-Match” with the ETag-value contained in the previous response from the server for that url. Now, if I programatically add the request-header “If-Modified-Since” and set it to a either a future or past date (doesn’t matter), the browser stops sending the “If-None-Match”-header. I have seen this in both FireFox and Chrome (not tested with any other browser). I can’t conclude from the HTTP/1.1 spec that this should be the case. Why does this happen?
Here is a simple code example that will reproduce the scenario. The code assumes that the server responds with an Etag-header.
var request = new XMLHttpRequest();
request.open("GET", someUrl, true);
request.onreadystatechange = function(){};
// This statement makes the browser stop sending the "If-None-Match" header
request.setRequestHeader("If-Modified-Since", "Sat, 29 Oct 1994 19:43:31 GMT");
request.send(null);
They shouldn’t, if the server provides in both an Etag and Last-Modified header for the given resource:
Edit: when calling
XmlHttpRequest.open(), the implementation prepares a request using annsIHttpChannel, using among others theIf-Modified-SinceandIf-None-Matchheaders if it can find a local cached item.Now when you call
SetRequestHeader()with eitherIf-(Un)Modified-SinceorIf-None-Match, it’ll clear both headers from the request and sets your value.