I ran into this issue with responses that set the Transfer-Encoding header, and are then fetched using a conditional get. Express caches the response, and determines whether it should respond with a 304. In those cases, the Content-Type and Content-Length headers are removed, but the Transfer-Encoding is not.
Upon a call to response.end(), node recognizes that the Transfer-Encoding: chunked header was set, and inserts an empty terminating chunk. For example:
HTTP/1.1 304 Not Modified
Date: Wed, 19 Dec 2012 00:05:09 GMT
But, per RFC 2616 §10.3.6 & §10.2.5 "The [204/304] response MUST NOT contain a message-body, and thus is always terminated by the first empty line after the header fields." This response it invalid.
I first brought this up with node (issue #4437), but they do not wish to modify headers as part of the HTTP module. However, this behavior can be prevented by removing the Transfer-Encoding header in express.
Explicitly remove Transfer-Encoding header from 204 and 304 responses
Per RFC 2616 §10.3.6 & §10.2.5 (http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html) "The [204/304] response MUST NOT contain a message-body, and thus is always terminated by the first empty line after the header fields."
nice catch thanks man