Unable to create HEAD response with completely empty body
See original GitHub issueSpring-Boot Version: 1.5.22.RELEASE
When creating a route with the method HEAD
in spring-boot, i.e.
@RequestMapping(value = "/", method = HEAD)
And you have chunked-encoding enabled by default, it doesn’t appear to be possible to return a response that is completely empty (which is required for HEAD
requests). For example if you do something like this
return ResponseEntity.status(OK).contentLength(0).build();
And analyze the bytes in the bodies response you get "0\r\n\r\n"
which indicates chunked encoding. This is illegal according to the RFC-spec, see https://tools.ietf.org/html/rfc7230#section-3.3 specifically
Responses to the HEAD request method (Section 4.3.2
of [RFC7231]) never include a message body because the associated
response header fields (e.g., Transfer-Encoding, Content-Length,
etc.), if present, indicate only what their values would have been if
the request method had been GET (Section 4.3.1 of [RFC7231]).
In other words, the response body should be completely empty. This is causing issues with certain http clients such as akka-http client which expect there to be no response in the body when making a HEAD
request. The related issue with akka-http can be seen here https://github.com/akka/akka-http/issues/2883#issuecomment-574070860
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (3 by maintainers)
So I just ran the app locally and I can confirm that its not spring-framework (by itself) that is adding these empty responses into the chunked body.
I will re-open the ticket if I find something to the contrary.
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.