senchalabs/connect — pull request #441 by jaekwon (2011-12-20 21:37:21+00:00)
Title: Bug(?) in use of res._headerSent vs res._header in calling _implicitHeaders

I was using 2.0.0alpha in master when the session middleware started crapping out. (see below)

This is caused by recent changes in middleware/session.js that checked res.headerSent (which checks res._headerSent), which is not the same as res._header.
>> I think _headerSent means whether the header was sent in the pipe, while _header means the _header was calculated and stored.

Upon further investigation I found that the _implicitHeaders() call in middleware/session.js is unnecessary, as node.js res.end() will call _implicitHeaders as necessary.

Along the way I also refactored compress.js. I removed revert(), which was confusing and seemed potentially dangerous in a middleware layer since other layers may depend on res.write/res.end being immutable. I reorganized some lines too.

Please review. Thanks for reading!

Error: Can't render headers after they are sent to the client.
at ServerResponse. (http.js:573:11)
at ServerResponse._renderHeaders (/Users/jae/workspace/src/harmonic/node_modules/connect/lib/patch.js:69:25)
at ServerResponse. (http.js:840:20)
at ServerResponse.writeHead (/Users/jae/workspace/src/harmonic/node_modules/connect/lib/patch.js:75:20)
at ServerResponse._implicitHeader (http.js:797:8)
at ServerResponse. (/Users/jae/workspace/src/harmonic/node_modules/connect/lib/middleware/session.js:231:32)
at ServerResponse.reply (/Users/jae/workspace/src/harmonic/lib/harmonic/router.coffee:40:21)
at ServerResponse.renderLayout (/Users/jae/workspace/src/harmonic/lib/harmonic/router.coffee:96:22)
at Route.fn (/Users/jae/workspace/src/harmonic/apps/default/index.coffee:14:24)
at /Users/jae/workspace/src/harmonic/lib/harmonic/router.coffee:78:16