HTTP RFC 9112 says that any response to HEAD request MUST NOT contain message body and Transfer-Encoding MAY be sent:
Transfer-Encoding MAY be sent in a response to a HEAD request or in a 304 (Not Modified) response (Section 15.4.5 of [HTTP]) to a GET request, neither of which includes a message body, to indicate that the origin server would have applied a transfer coding to the message body if the request had been an unconditional GET. This indication is not required, however, because any recipient on the response chain (including the origin server) can remove transfer codings when they are not needed.
However, the same RFC in 7.1 says that if Tansfer-Encoding is chunked it must contain chunk-size, which is message body (and must not be in HEAD response):
The chunked transfer coding wraps content in order to transfer it as a series of chunks, each with its own size indicator, followed by an OPTIONAL trailer section containing trailer fields.
ElasticSearch is sending Transfer-Encoding: chunked
in response to HEAD without chunk-size
and HAProxy does have a problem with it .
How should I interpret it?
HTTP RFC 9112 says that any response to HEAD request MUST NOT contain message body and Transfer-Encoding MAY be sent:
Transfer-Encoding MAY be sent in a response to a HEAD request or in a 304 (Not Modified) response (Section 15.4.5 of [HTTP]) to a GET request, neither of which includes a message body, to indicate that the origin server would have applied a transfer coding to the message body if the request had been an unconditional GET. This indication is not required, however, because any recipient on the response chain (including the origin server) can remove transfer codings when they are not needed.
However, the same RFC in 7.1 says that if Tansfer-Encoding is chunked it must contain chunk-size, which is message body (and must not be in HEAD response):
The chunked transfer coding wraps content in order to transfer it as a series of chunks, each with its own size indicator, followed by an OPTIONAL trailer section containing trailer fields.
ElasticSearch is sending Transfer-Encoding: chunked
in response to HEAD without chunk-size
and HAProxy does have a problem with it https://github.com/haproxy/haproxy/issues/2836.
How should I interpret it?
Yes, including a Transfer-Encoding: chunked
header in response to a HEAD
request is valid. As you point out, that is explicitly acknowledged in Section 6.1 of RFC 9112.
Section 7.1 doesn't contradict that, it simply defines the grammar used when sending chunked data. But the whole point of HEAD
is to send those headers you would have sent with a GET
, but without a body. So, similarly, Transfer-Encoding: gzip
will give an response empty body, Content-Length
won't match the length (0) of the HEAD
response body, etc. Put differently, the semantics of a HEAD
response are different and the body is not expected to match the headers.
In the issue you mention HAProxy acknowledges that their rejection was a bug, and they provide a fix.