Skip to content

Loading…

Fix response headers #34

Merged
merged 3 commits into from

2 participants

@cliffano

Cache-Control field value should be comma separated as per http://tools.ietf.org/html/rfc2616 (message-header field-value format).

Vary header should be added since content negotiation is supported.
http://stackoverflow.com/questions/7848796/what-does-varyaccept-encoding-mean
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.44

@cliffano

I noticed that connect-assetmanager keeps returning status code 200 even though the browser already caches the resource on disk. So I added If-Modified-Since request header handling as per RFC 2616 14.25
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.25

@mape mape merged commit 5c0eeb9 into mape:master
@mape
Owner

Thanks for the pull req :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Showing with 11 additions and 4 deletions.
  1. +11 −4 lib/assetmanager.js
View
15 lib/assetmanager.js
@@ -387,16 +387,23 @@ module.exports = function assetManager (assets) {
'Content-Length': response.contentLength,
'Last-Modified': response.modified,
'Date': (new Date).toUTCString(),
- 'Cache-Control': 'public max-age=' + 31536000,
- 'Expires': response.expires || (new Date(new Date().getTime()+63113852000)).toUTCString()
+ 'Cache-Control': 'public,max-age=' + 31536000,
+ 'Expires': response.expires || (new Date(new Date().getTime()+63113852000)).toUTCString(),
+ 'Vary': 'Accept-Encoding'
};
if(response.encoding) {
headers['Content-Encoding'] = response.encoding
}
- res.writeHead(200, headers);
- res.end(response.contentBuffer);
+ if (req.headers['if-modified-since'] &&
+ Date.parse(req.headers['if-modified-since']) >= Date.parse(response.modified)) {
+ res.writeHead(304, headers);
+ res.end();
+ } else {
+ res.writeHead(200, headers);
+ res.end(response.contentBuffer);
+ }
}
return;
}
Something went wrong with that request. Please try again.