Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Don't respond with 304 when error status is passed in (status >= 400). #59

Closed
wants to merge 1 commit into from

2 participants

@pbouzakis

No description provided.

@phstc
Collaborator

Hi @pbouzakis, could you re merge it?

@phstc phstc closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 9 additions and 10 deletions.
  1. +9 −10 lib/node-static.js
View
19 lib/node-static.js
@@ -186,22 +186,21 @@ this.Server.prototype.respond = function (pathname, status, _headers, files, sta
headers['Date'] = new(Date)().toUTCString();
headers['Last-Modified'] = new(Date)(stat.mtime).toUTCString();
- // Conditional GET
- // If the "If-Modified-Since" or "If-None-Match" headers
- // match the conditions, send a 304 Not Modified.
- if (req.headers['if-none-match'] === headers['ETag'] ||
- Date.parse(req.headers['if-modified-since']) >= mtime) {
- finish(304, headers);
- } else if (req.method === 'HEAD') {
- finish(200, headers);
+ for (var k in _headers) { headers[k] = _headers[k]; }
+
+ // Only check for conditional GET when the status of the request is not set to an error code.
+ if (status < 400 && (req.headers['if-none-match'] === headers['ETag'] ||
+ Date.parse(req.headers['if-modified-since']) >= mtime)) {
+ // Conditional GET
+ // If the "If-Modified-Since" or "If-None-Match" headers
+ // match the conditions, send a 304 Not Modified.
+ finish(304, headers);
} else {
var fileExtension = path.extname(files[0]).slice(1).toLowerCase();
headers['Content-Length'] = stat.size;
headers['Content-Type'] = mime.contentTypes[fileExtension] ||
'application/octet-stream';
- for (var k in _headers) { headers[k] = _headers[k] }
-
res.writeHead(status, headers);
// If the file was cached and it's not older
Something went wrong with that request. Please try again.