expressjs/session — pull request #102 by mctep (2014-11-26 17:29:41+00:00)
Title: res.end should finish response

Hello. Thanks for your job.

I have some code in express:
```js
var express = require('express');
var session = require('express-session');
var request = require('supertest');

var app = express();

app.use(session({
resave: true,
saveUninitialized: true,
secret: 'test'
}));

app.get('/',
function(req, res, next) {
var someBigIsolateLogic = true;
if (someBigIsolateLogic) {
res.send('I have some result');
}

// I don't know about big logic
// and what it have to send or not send.
//
// I have to send default content.
if (!res.finished) {
res.send('Default result');
}
}
);

request(app).get('/').expect(200).end(function() {});
```

In some places I rely on the `res.finished` to find out whether the response has finished. And if it has not, I send the default result.

But the code above throws the `Error('Can't set headers after they are sent.')` because the original `req.end` is called asynchronously, and it doesn't set the `req.finished` as `true` at the right time. And without using session this code works as expected.

My PR resolves this problem, and I think it looks like hack. But I worked out nothing better.