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: setting Content-Type header to []string{""} in http handler causes two Content-Type headers to be emitted #13495

Closed
odeke-em opened this issue Dec 5, 2015 · 2 comments

Comments

Projects
None yet
2 participants
@odeke-em
Copy link
Member

commented Dec 5, 2015

This issue is a followup of #5953 which was noticed during a port of tests to http2 in CL https://go-review.googlesource.com/#/c/17462/ or in code

diff --git a/src/net/http/sniff_test.go b/src/net/http/sniff_test.go
index 293a7f5..a372210 100644
--- a/src/net/http/sniff_test.go
+++ b/src/net/http/sniff_test.go
@@ -88,15 +88,18 @@ func testServerContentType(t *testing.T, h2 bool) {

 // Issue 5953: shouldn't sniff if the handler set a Content-Type header,
 // even if it's the empty string.
-func TestServerIssue5953(t *testing.T) {
+func TestServerIssue5953_h1(t *testing.T) { testServerIssue5953(t, false) }
+func TestServerIssue5953_h2(t *testing.T) { testServerIssue5953(t, true) }
+
+func testServerIssue5953(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()["Content-Type"] = []string{""}
        fmt.Fprintf(w, "<html><head></head><body>hi</body></html>")
    }))
-   defer ts.Close()
+   defer cst.close()

-   resp, err := Get(ts.URL)
+   resp, err := cst.c.Get(cst.ts.URL)
    if err != nil {
        t.Fatal(err)
    }
$ go test --cover
--- FAIL: TestServerIssue5953_h2 (0.00s)
    sniff_test.go:110: Content-Type = ["" "text/html; charset=utf-8"]; want [""]
FAIL
coverage: 77.4% of statements
exit status 1
FAIL    net/http    22.409s

@mikioh mikioh changed the title net/http2: setting Content-Type header to []string{""} in http handler causes two Content-Type headers to be emitted net/http: setting Content-Type header to []string{""} in http handler causes two Content-Type headers to be emitted Dec 8, 2015

@gopherbot

This comment has been minimized.

Copy link

commented Dec 9, 2015

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

@gopherbot

This comment has been minimized.

Copy link

commented Dec 9, 2015

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

bradfitz added a commit to golang/net that referenced this issue Dec 9, 2015

http2: fix two cases of Server behavior not matching HTTP/1
* don't send automatic Content-Length from Server on HEAD requests if
  response size is 0 (it's possible the handler didn't write because
  they looked at the method)

* don't send Content-Type if handler explicitly set it to nothing.

Matches the behavior of HTTP/1.

Updates golang/go#13532
Updates golang/go#13495

Change-Id: If6e0898095cf88cb14efb6bbe82c88dbc2077e6b
Reviewed-on: https://go-review.googlesource.com/17590
Reviewed-by: Blake Mizerany <blake.mizerany@gmail.com>

@bradfitz bradfitz closed this in 3d3d6eb Dec 9, 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.