check for http.NoBody as well as nil Body #5
+2
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While converting some internal services to use HTTPS instead of HTTP, we were observing breakages related to having
Transfer-Encoding: chunked
andContent-Length: -1
onGET
requests, which makes little sense. After some long debugging sessions, we finally located the cause: The internal Go http client is upgrading the request to HTTP2, and the code that determines the actual content length requires either anil
body orhttp.NoBody
to send aContent-Length
of 0. Since the check forhttp.NoBody
was not here, an empty byte buffer was being created, which failed the checks and caused aContent-Length
of -1 to be used elsewhere. Adding the check here fixes the problem for us.(We use echo and it really does not like
Content-Length: -1
when binding requests to structs, event forGET
requests.)