express icon indicating copy to clipboard operation
express copied to clipboard

Do not auto-remove content headers for body-less status codes

Open LJ1102 opened this issue 6 months ago • 2 comments

According to RFC 2616 (HTTP/1.1 spec) a HEAD request is supposed to return exactly the same entity-headers as a GET request but no body, ~~imho responding to such a request with a 204 status code seems reasonable, thus we should not remove any headers but only ensure that no body is sent.~~

LJ1102 avatar Nov 16 '23 18:11 LJ1102

I did some more digging and in fact RFC 7230 specifies the following:

Transfer-Encoding MAY be sent in a response to a HEAD request or in a 304 (Not Modified) response

A server MAY send a Content-Length header field in a 304 (Not Modified) response to a conditional GET request

A server MUST NOT send a Content-Length header field in any response with a status code of 1xx (Informational) or 204 (No Content).

So I altered my changes (and adjusted the unit tests) to be compliant to that, so that with a 304 we leave the content-headers untouched, but on 204 we remove them.

LJ1102 avatar Nov 17 '23 03:11 LJ1102

write clean code

TahsinAyman avatar Dec 08 '23 15:12 TahsinAyman