Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

proxy writeHead on response object

  • Loading branch information...
commit f7e7b3e015729371753cb9a4bfa7a6f6648c890a 1 parent 51a68e0
@caolan authored
Showing with 8 additions and 8 deletions.
  1. +4 −4 lib/cookie-sessions.js
  2. +4 −4 test/test-cookie-sessions.js
View
8 lib/cookie-sessions.js
@@ -127,11 +127,11 @@ exports.filter = function(settings){
s.session_key, s.secret, s.timeout, req);
// proxy writeHead to add cookie to response
- var _writeHead = req.writeHead;
- req.writeHead = function(){
+ var _writeHead = res.writeHead;
+ res.writeHead = function(){
var args = Array.prototype.slice.call(arguments);
- var headers = args[args.length-1];
+ var headers = (args.length > 1) ? args[args.length-1] : {};
// Add a Set-Cookie header to all responses with the session data
// and the current timestamp. The cookie needs to be set on every
@@ -141,7 +141,7 @@ exports.filter = function(settings){
escape(exports.serialize(s.secret, req.session));
// call the original writeHead on the request
- return _writeHead.apply(req, args);
+ return _writeHead.apply(res, args);
}
next();
View
8 test/test-cookie-sessions.js
@@ -331,8 +331,8 @@ exports['writeHead'] = function(test){
secret: 'secret',
timeout: 86400
};
- var req = {
- headers: {},
+ var req = {headers: {}};
+ var res = {
writeHead: function(code, headers){
test.equals(headers['Set-Cookie'], '_node=serialized_session');
test.equals(headers['original'], 'header');
@@ -349,12 +349,12 @@ exports['writeHead'] = function(test){
var next = function(){
test.ok(true, 'chain.next called');
req.session = {test:'test'};
- req.writeHead(200, {'original':'header'});
+ res.writeHead(200, {'original':'header'});
// restore copied functions
sessions.serialize = serialize;
test.done();
};
- sessions.filter(s)(req, 'res', next);
+ sessions.filter(s)(req, res, next);
};
exports['onInit secret set'] = function(test){
Please sign in to comment.
Something went wrong with that request. Please try again.