]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: test and document suppressing implicit Content-Type response header
authorBrad Fitzpatrick <bradfitz@golang.org>
Tue, 28 Apr 2015 02:32:00 +0000 (19:32 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 28 Apr 2015 20:49:08 +0000 (20:49 +0000)
No code changes.

Fixes #8992

Change-Id: I10c8340a4f8e3e7add9b3ac5aa0a1e8d8aa49f40
Reviewed-on: https://go-review.googlesource.com/9412
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>

src/net/http/serve_test.go
src/net/http/server.go

index 6e1b3ed0251f07f90cb308a4b8cba3a68d5c7da4..be544874411e779b132a761b5836a410c2acf316 100644 (file)
@@ -1452,19 +1452,23 @@ func testHandlerPanic(t *testing.T, withHijack bool, panicValue interface{}) {
        }
 }
 
-func TestNoDate(t *testing.T) {
+func TestServerNoDate(t *testing.T)        { testServerNoHeader(t, "Date") }
+func TestServerNoContentType(t *testing.T) { testServerNoHeader(t, "Content-Type") }
+
+func testServerNoHeader(t *testing.T, header string) {
        defer afterTest(t)
        ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {
-               w.Header()["Date"] = nil
+               w.Header()[header] = nil
+               io.WriteString(w, "<html>foo</html>") // non-empty
        }))
        defer ts.Close()
        res, err := Get(ts.URL)
        if err != nil {
                t.Fatal(err)
        }
-       _, present := res.Header["Date"]
-       if present {
-               t.Fatalf("Expected no Date header; got %v", res.Header["Date"])
+       res.Body.Close()
+       if got, ok := res.Header[header]; ok {
+               t.Fatalf("Expected no %s header; got %q", header, got)
        }
 }
 
index 565c87d3929b1cf454e2ae8bb6c7052924937082..1bde413a381193e15962b389a3a7896e6dac8dcb 100644 (file)
@@ -61,6 +61,7 @@ type ResponseWriter interface {
        // WriteHeader (or Write) has no effect unless the modified
        // headers were declared as trailers by setting the
        // "Trailer" header before the call to WriteHeader.
+       // To suppress implicit response headers, set their value to nil.
        Header() Header
 
        // Write writes the data to the connection as part of an HTTP reply.