-
Notifications
You must be signed in to change notification settings - Fork 18k
net/http: Transfer-Encoding: chunked is sometimes used when making HTTP2 requests #43303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
cc @fraenkel |
@spantaleev can you collect the http2debug logs for the client so we can see what is being sent? It's going to be difficult without a way to reproduce this. |
Testing with this code: package main
import (
"fmt"
"net/http"
"bytes"
"io/ioutil"
)
func main() {
payloadBytes := []byte("{\"key\": \"value\"}")
request, err := http.NewRequest(
"POST",
"https://example.com/api",
bytes.NewReader(payloadBytes),
)
if err != nil {
panic(err)
}
request.Header.Set("Content-Type", "application/json")
request.Header.Set("Authorization", "Bearer XXXXXXXXXXXX")
request.ContentLength = 0
resp, err := http.DefaultClient.Do(request)
if err != nil {
panic(err)
}
defer resp.Body.Close()
bodyBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Println(string(bodyBytes))
} The faulty server is Apache/2.4.46 (Ubuntu) OpenSSL/1.1.1.
The request headers are dumped into the response body and I can see Here's what I get for another server (nginx/1.18.0), where it's all fine:
Hope this is helpful! |
Sorry but I don't see them client ever sending chunked. If there server side is saying so it is broken. The only other difference I see is one is sending a gzipped response which is allowed. |
Thanks for checking it out! I suppose the problem lies somewhere on the server side then. Perhaps there's some reverse-proxy somewhere or something. It will be reported to the service provider. Sorry for wasting your time on this! |
What version of Go are you using (
go version
)?Using
docker.io/golang:1.15.6-alpine3.12
It's the same on 1.15.2 though. So I wouldn't say it's some new regression.
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I can't reproduce it with a server of my own, but I had another person (on shared Apache hosting) show me the request headers (in PHP). We saw that it's an HTTP2 connection and that there's a
Transfer-Encoding: chunked
request header.The original problem was that he couldn't read the request body (JSON).. We tracked it down to this. As soon as we set
.ContentLength
explicitly, Go's HTTP client no longer setsTransfer-Encoding: chunked
and the problem goes away.The same code (even without explicitly setting
.ContentLength
) works as expected on HTTP2-capable servers of mine (nginx).So it seems to be some weird interaction between that specific Apache version (which is unknown so far) and Golang's HTTP client. There may be some reverse-proxies inbetween, so it may be something else's fault entirely (not Golang's HTTP client).
Unfortunately, I neither have an HTTP2-capable Apache server of mine, nor do I know the exact Apache version that his shared hosting provider runs.
Obviously, there's lack of information about this (Apache version used, whether there are other reverse-proxies involved, etc.), but perhaps this is still enough to track down the problem of
net/http
's willingness to combine HTTP2 withchunked
transfer encoding under weird circumstances..? Again, that is, unless something else (some reverse-proxy) is actually causing this.The text was updated successfully, but these errors were encountered: