visionmedia/express — pull request #1451 by aweeks (2012-12-19 19:07:54+00:00)
Title: Explicitly remove Transfer-Encoding header from 204 and 304 responses

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
Transfer-Encoding: chunked
Date: Wed, 19 Dec 2012 00:05:09 GMT
Connection: keep-alive

0

```

But, per [RFC 2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html) §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](https://github.com/joyent/node/issues/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.