Permalink
Browse files

update writeHead to match node API

  • Loading branch information...
1 parent 4750436 commit 51a68e0261c7c4ddb0fa45d8e651219679c3a32f @caolan committed Jul 28, 2010
Showing with 7 additions and 4 deletions.
  1. +5 −2 lib/cookie-sessions.js
  2. +2 −2 test/test-cookie-sessions.js
@@ -128,7 +128,10 @@ exports.filter = function(settings){
// proxy writeHead to add cookie to response
var _writeHead = req.writeHead;
- req.writeHead = function(headers){
+ req.writeHead = function(){
+
+ var args = Array.prototype.slice.call(arguments);
+ var headers = 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
@@ -138,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, Array.prototype.slice.call(arguments));
+ return _writeHead.apply(req, args);
}
next();
@@ -333,7 +333,7 @@ exports['writeHead'] = function(test){
};
var req = {
headers: {},
- writeHead: function(headers){
+ writeHead: function(code, headers){
test.equals(headers['Set-Cookie'], '_node=serialized_session');
test.equals(headers['original'], 'header');
}
@@ -349,7 +349,7 @@ exports['writeHead'] = function(test){
var next = function(){
test.ok(true, 'chain.next called');
req.session = {test:'test'};
- req.writeHead({'original':'header'});
+ req.writeHead(200, {'original':'header'});
// restore copied functions
sessions.serialize = serialize;
test.done();

0 comments on commit 51a68e0

Please sign in to comment.