Skip to content
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

net/http: server responds with Transfer-Encoding: identity #49194

Closed
neild opened this issue Oct 27, 2021 · 7 comments
Closed

net/http: server responds with Transfer-Encoding: identity #49194

neild opened this issue Oct 27, 2021 · 7 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.

Comments

@neild
Copy link
Contributor

neild commented Oct 27, 2021

The net/http server permits setting a Transfer-Encoding: identity header to disable chunked response writes. As of https://golang.org/cl/231418, the net/http client rejects responses with Transfer-Encoding: identity, resulting in cases where a Go client cannot talk to a Go server.

Example case:

func main() {
        http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
                w.Header().Set("Transfer-Encoding", "identity")
                w.WriteHeader(200)
                w.(http.Flusher).Flush()
                fmt.Fprintln(w, "Hello, world.")
        })
        go func() {
                log.Fatal(http.ListenAndServe("127.0.0.1:8080", nil))
        }()
        time.Sleep(1 * time.Second)

        _, err := http.Get("http://127.0.0.1:8080/")
        if err != nil {
                fmt.Println(err)
        }
}
Get "http://127.0.0.1:8080/": net/http: HTTP/1.x transport connection broken: unsupported transfer encoding: "identity"

The server should remove the Transfer-Encoding: identity header from the response (while still disabling chunking).

Related: The server should treat any encoding other than "identity" or "chunked" as an error. https://golang.org/issue/38867

@gopherbot
Copy link

Change https://golang.org/cl/359176 mentions this issue: net/http: do not send Transfer-Encoding: identity in responses

@seankhliao seankhliao added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 28, 2021
@neild
Copy link
Contributor Author

neild commented Nov 12, 2021

@gopherbot Please open backport issues for 1.16 and 1.17

@gopherbot
Copy link

Backport issue(s) opened: #49567 (for 1.16), #49568 (for 1.17).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://golang.org/wiki/MinorReleases.

@gopherbot
Copy link

Change https://golang.org/cl/368086 mentions this issue: [release-branch.go1.16] net/http: do not send Transfer-Encoding: identity in responses

@gopherbot
Copy link

Change https://golang.org/cl/368087 mentions this issue: [release-branch.go1.17] net/http: do not send Transfer-Encoding: identity in responses

gopherbot pushed a commit that referenced this issue Dec 1, 2021
…tity in responses

Server handlers may set a "Transfer-Encoding: identity" header on
responses to disable chunking, but this header should not be sent
on the wire.

For #49194.
Fixes #49568.

Change-Id: I46a9e3b8ff9d93edd7d1c34d264fc309fa322ad5
Reviewed-on: https://go-review.googlesource.com/c/go/+/359176
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
(cherry picked from commit b69b2f6)
Reviewed-on: https://go-review.googlesource.com/c/go/+/368087
Reviewed-by: Michael Knyszek <mknyszek@google.com>
gopherbot pushed a commit that referenced this issue Dec 1, 2021
…tity in responses

Server handlers may set a "Transfer-Encoding: identity" header on
responses to disable chunking, but this header should not be sent
on the wire.

For #49194.
Fixes #49567.

Change-Id: I46a9e3b8ff9d93edd7d1c34d264fc309fa322ad5
Reviewed-on: https://go-review.googlesource.com/c/go/+/359176
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
(cherry picked from commit b69b2f6)
Reviewed-on: https://go-review.googlesource.com/c/go/+/368086
Reviewed-by: Michael Knyszek <mknyszek@google.com>
@halegreen
Copy link

halegreen commented Jun 4, 2022

I got transfer-encoding header missing in http response header by using the following code to complete request.
While using curl to the same URL is OK, but don't know why ?

	client := &http.Client{}
	resp, err := client.Get(url)
	if err != nil {
		fmt.Errorf("%v", err)
	} else {
		for k, v := range resp.Header {
			fmt.Printf("k:%s, v:%s \n", k, v)
		}
	}

@neild
Copy link
Contributor Author

neild commented Jun 6, 2022

I got transfer-encoding header missing in http response header by using the following code to complete request.
While using curl to the same URL is OK, but don't know why ?

What is the value of url? What headers did you see? What did you expect to see?

@golang golang locked and limited conversation to collaborators Jun 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants