flatiron/union — Issue #21: connect session not working
Author: amelon
Created: 2012-02-23 17:40:36+00:00
State: open

there's still issue with connect session middleware and union:

-union: 0.1.7
-flatiron: 0.1.11
-connect: 2.0.0alpha1

As mentioned, `connect` patch `ServerResponse` prototype to support event `"header"`. (`connect/lib/patch.js`)
On `session` middleware, `connect` expect the response parameter to be a `http.ServerResponse` and it listens to `"header"` event to write cookie header.
(line 221 on `connect/lib/middleware/session.js`)

```javascript
// set-cookie
res.on('header', function(){
if (!req.session) return;
var cookie = req.session.cookie
, proto = (req.headers['x-forwarded-proto'] || '').toLowerCase()
, tls = req.connection.encrypted || (trustProxy && 'https' == proto)
, secured = cookie.secure && tls;

// browser-session cookies only set-cookie once
if (null == cookie.expires && !sessionIsNew) return;

// only send secure cookies via https
if (cookie.secure && !secured) return debug('not secured');

debug('set %s to %s', key, req.sessionID);
res.setHeader('Set-Cookie', cookie.serialize(key, req.sessionID));
});
```

As response object forwarded by `union` to `connect` is a `ResponseStream` object, `"header"` event is never emit.

row

```javascript
// set-cookie
res.on('header', function(){

```

should be

```javascript
// set-cookie
res.response.on('header', function(){

```

no idea of how to work around this issue