Explicitly remove Transfer-Encoding header from 204 and 304 responses #1451

Merged
merged 1 commit into from Dec 19, 2012

Projects

None yet

2 participants

@aweeks
Contributor
aweeks commented Dec 19, 2012

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 §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.

@aweeks aweeks 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."
a1e42ac
@tj
Member
tj commented Dec 19, 2012

nice catch thanks man

@tj tj merged commit 3c4fd57 into expressjs:master Dec 19, 2012

1 check passed

default The Travis build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment