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

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

Comments

@odeke-em
Copy link
Member

odeke-em 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 https://go-review.googlesource.com/#/c/17598/2

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 {
        t.Fatal(err)
    }

Giving

$ go test -cover
--- FAIL: TestServeFileWithContentEncoding_h2 (0.00s)
    fs_test.go:501: Content-Length mismatch: got 11, want -1
FAIL
coverage: 78.2% of statements
exit status 1
FAIL    net/http    22.996s
@bradfitz bradfitz self-assigned this Dec 9, 2015
@gopherbot
Copy link

CL https://golang.org/cl/17683 mentions this issue.

@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.
Projects
None yet
Development

No branches or pull requests

3 participants