question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to create HEAD response with completely empty body

See original GitHub issue

Spring-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:closed
  • Created 4 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mdedetrichcommented, Jan 23, 2020

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.

0reactions
spring-projects-issuescommented, Jan 23, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

IE sometimes making HEAD request with empty body instead ...
We have a strange situation with our web application. We have several pages with HTML-forms on them. When the user presses a button...
Read more >
HEAD - HTTP - MDN Web Docs
The HTTP HEAD method requests the headers that would be returned if the HEAD request's URL was instead requested with the HTTP GET...
Read more >
Understanding HEAD, HTTP/204 and HTTP/206 - Telerik
The HEAD method allows the client to query the server for the headers for a given resource without actually downloading the resource itself....
Read more >
HTTP/1.1: Method Definitions
The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response. The metainformation contained in...
Read more >
HTTP Client - Laravel - The PHP Framework For Web Artisans
If all of the requests fail, an instance of Illuminate\Http\Client\RequestException will be thrown. If you would like to disable this behavior, you may...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found