Skip to content

Loading…

Sending custom headers even on 304 (Not Modified) response. #96

Merged
merged 1 commit into from

2 participants

@donebizkit

When a 304 (Not Modified) response is sent, user defined headers are not sent. Only default headers are.
In my case scenario, I need to update the "Set-Cookie" header to extend it every time a user accesses a page. So, even though the page has not changed, therefore generating a 304 response, I still need to send "Set-Cookie" header with a new expiration timestamp.

@donebizkit donebizkit Send custom headers even on a 304 Not Modified case
When a 304 (Not Modified) response is sent, user defined headers are not sent. Only default headers are.
In my case scenario, I need to update the "Set-Cookie" header to extend it every time a user accesses a page. So, even though the page has not changed, therefore generating a 304 response, I still need to send "Set-Cookie" header with a new expiration timestamp.
a364b0c
@phstc phstc merged commit 2760f37 into cloudhead:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 2, 2013
  1. @donebizkit

    Send custom headers even on a 304 Not Modified case

    donebizkit committed
    When a 304 (Not Modified) response is sent, user defined headers are not sent. Only default headers are.
    In my case scenario, I need to update the "Set-Cookie" header to extend it every time a user accesses a page. So, even though the page has not changed, therefore generating a 304 response, I still need to send "Set-Cookie" header with a new expiration timestamp.
Showing with 2 additions and 2 deletions.
  1. +2 −2 lib/node-static.js
View
4 lib/node-static.js
@@ -203,6 +203,8 @@ Server.prototype.respond = function (pathname, status, _headers, files, stat, re
// Copy default headers
for (var k in this.options.headers) { headers[k] = this.options.headers[k] }
+ // Copy custom headers
+ for (var k in _headers) { headers[k] = _headers[k] }
headers['etag'] = JSON.stringify([stat.ino, stat.size, mtime].join('-'));
headers['date'] = new(Date)().toUTCString();
@@ -220,8 +222,6 @@ Server.prototype.respond = function (pathname, status, _headers, files, stat, re
headers['content-type'] = mime.lookup(files[0]);
'application/octet-stream';
- for (var k in _headers) { headers[k] = _headers[k] }
-
res.writeHead(status, headers);
if (req.method === 'HEAD') {
Something went wrong with that request. Please try again.