This could potentially be seen as a couple of different issues, but they're all tightly overlapping, and can probably all be solved with a common fix. This also overlaps with #2215.
Currently, Content-Length: 0 may be automatically applied to any 204 response (just like 101 responses in #2215). Also, other Content-Length headers can be set explicitly within a service, or be implied by a body with a KnownLength. A 204 response MUST NOT contain either Content-Length or Transfer-Encoding.
On the other hand, a 304 response will never have a body, but MAY contain either Content-Length or Transfer-Encoding. Currently, the only way to get a Content-Length header attached to a 304 response is to try to actually send a Body of that length.
The headers made in response to a HEAD request should match those which would have been made for a GET request. Currently, if a service attempts to force chunked encoding on what might otherwise imply a Content-Length header be added, GET requests will see Transfer-Encoding: chunked while a HEAD request receives Content-Length: .... It is not currently possible to set Transfer-Encoding on a response to a HEAD request.
It seems the things which need to be fixed are:
For reference, https://httpwg.org/specs/rfc7230.html#rfc.section.3.3
This could potentially be seen as a couple of different issues, but they're all tightly overlapping, and can probably all be solved with a common fix. This also overlaps with #2215.
Currently,
Content-Length: 0may be automatically applied to any 204 response (just like 101 responses in #2215). Also, otherContent-Lengthheaders can be set explicitly within a service, or be implied by a body with aKnownLength. A 204 response MUST NOT contain eitherContent-LengthorTransfer-Encoding.On the other hand, a 304 response will never have a body, but MAY contain either
Content-LengthorTransfer-Encoding. Currently, the only way to get aContent-Lengthheader attached to a 304 response is to try to actually send a Body of that length.The headers made in response to a
HEADrequest should match those which would have been made for aGETrequest. Currently, if a service attempts to force chunked encoding on what might otherwise imply aContent-Lengthheader be added,GETrequests will seeTransfer-Encoding: chunkedwhile aHEADrequest receivesContent-Length: .... It is not currently possible to setTransfer-Encodingon a response to aHEADrequest.It seems the things which need to be fixed are:
CONNECTrequest, anyContent-LengthorTransfer-Encodingheader set by a service must be dropped. Further, neither header should be automatically added.Content-LengthorTransfer-Encodingheader set by a service for any kind of response should be handled the same forGETandHEADrequests.Content-LengthorTransfer-Encodingheader set by a service for a 304 response should be left alone. (perhaps unless aBodySize::Knowngreater than 0 conflicts with aContent-Lengthheader, which could be an error?)For reference, https://httpwg.org/specs/rfc7230.html#rfc.section.3.3