diff --git a/index.js b/index.js index 35ea5a84..a16713a9 100644 --- a/index.js +++ b/index.js @@ -193,7 +193,7 @@ function session(options){ var ret; var sync = true; - if (chunk === undefined) { + if (chunk === undefined || chunk === null) { chunk = ''; } diff --git a/test/session.js b/test/session.js index 0481d78c..8b0e510a 100644 --- a/test/session.js +++ b/test/session.js @@ -184,6 +184,34 @@ describe('session()', function(){ .expect(200, 'Hello, world!', done); }) + it('should handle HEAD requests which respond with undefined bodies', function (done) { + var app = express() + + app.use(createSession()) + app.use(function (req, res) { + res.setHeader('Content-Length', 1) + res.end(undefined, 'utf8') + }) + + request(app) + .head('/') + .expect(200, '', done) + }) + + it('should handle HEAD requests which respond with null bodies', function (done) { + var app = express() + + app.use(createSession()) + app.use(function (req, res) { + res.setHeader('Content-Length', 1) + res.end(null, 'utf8') + }) + + request(app) + .head('/') + .expect(200, '', done) + }) + describe('when response ended', function () { it('should have saved session', function (done) { var saved = false