Skip to content

Commit

Permalink
Fix content headers being sent in 304 response
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Sep 15, 2014
1 parent 7003312 commit 8a2614f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
unreleased
==========

* Fix content headers being sent in 304 response
* deps: etag@~1.3.1
- Improve ETag generation speed

Expand Down
27 changes: 18 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,8 @@ function createIcon(buf, maxAge) {
return {
body: buf,
headers: {
'Content-Type': 'image/x-icon',
'Content-Length': buf.length,
'Cache-Control': 'public, max-age=' + ~~(maxAge / 1000),
'etag': etag(buf)
'ETag': etag(buf)
}
};
}
Expand All @@ -106,11 +104,22 @@ function createIsDirError(path) {
return error;
}

function send(req, res, icon){
var _fresh = fresh(req.headers, icon.headers);
var buf = _fresh ? '' : icon.body;
var status = _fresh ? 304 : 200;
function send(req, res, icon) {
var headers = icon.headers;

res.writeHead(status, icon.headers);
res.end(buf);
// Set headers
for (var header in headers) {
res.setHeader(header, headers[header]);
}

if (fresh(req.headers, res._headers)) {
res.statusCode = 304;
res.end();
return;
}

res.statusCode = 200;
res.setHeader('Content-Length', icon.body.length);
res.setHeader('Content-Type', 'image/x-icon');
res.end(icon.body);
}

0 comments on commit 8a2614f

Please sign in to comment.