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: discrepancy in contentLength given invalid "Content-Encoding":"foo" between http1 and http2 #13543

odeke-em opened this issue Dec 9, 2015 · 1 comment


None yet
3 participants
Copy link

commented Dec 9, 2015

Setting an invalid "Content-Encoding" as "foo" then querying for resp.ContentLength in http1 returns -1 while in http2 it returns the entire length of the content served.
The test's CL that found this is at

diff --git a/src/net/http/fs_test.go b/src/net/http/fs_test.go
index 7550c55..1d52678 100644
--- a/src/net/http/fs_test.go
+++ b/src/net/http/fs_test.go
@@ -477,14 +477,22 @@ func TestServeFileFromCWD(t *testing.T) {

-func TestServeFileWithContentEncoding(t *testing.T) {
+func TestServeFileWithContentEncoding_h1(t *testing.T) {
+   testServeFileWithContentEncoding(t, false)
+func TestServeFileWithContentEncoding_h2(t *testing.T) {
+   testServeFileWithContentEncoding(t, true)
+func testServeFileWithContentEncoding(t *testing.T, h2 bool) {
    defer afterTest(t)
-   ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {
+   cst := newClientServerTest(t, h2, HandlerFunc(func(w ResponseWriter, r *Request) {
        w.Header().Set("Content-Encoding", "foo")
        ServeFile(w, r, "testdata/file")
-   defer ts.Close()
-   resp, err := Get(ts.URL)
+   defer cst.close()
+   resp, err := cst.c.Get(cst.ts.URL)
    if err != nil {


$ go test -cover
--- FAIL: TestServeFileWithContentEncoding_h2 (0.00s)
    fs_test.go:501: Content-Length mismatch: got 11, want -1
coverage: 78.2% of statements
exit status 1
FAIL    net/http    22.996s

@bradfitz bradfitz self-assigned this Dec 9, 2015


This comment has been minimized.

Copy link

commented Dec 9, 2015

CL mentions this issue.

@bradfitz bradfitz closed this in c2ef005 Dec 10, 2015

@golang golang locked and limited conversation to collaborators Dec 14, 2016

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.