Commit 5ed44e9d authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

net/http: test and document suppressing implicit Content-Type response header

No code changes.

Fixes #8992

Change-Id: I10c8340a4f8e3e7add9b3ac5aa0a1e8d8aa49f40
Reviewed-on: https://go-review.googlesource.com/9412Reviewed-by: default avatarDavid Crawshaw <crawshaw@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
parent d3bd6b6a
...@@ -1452,19 +1452,23 @@ func testHandlerPanic(t *testing.T, withHijack bool, panicValue interface{}) { ...@@ -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) defer afterTest(t)
ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) { 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() defer ts.Close()
res, err := Get(ts.URL) res, err := Get(ts.URL)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
_, present := res.Header["Date"] res.Body.Close()
if present { if got, ok := res.Header[header]; ok {
t.Fatalf("Expected no Date header; got %v", res.Header["Date"]) t.Fatalf("Expected no %s header; got %q", header, got)
} }
} }
......
...@@ -61,6 +61,7 @@ type ResponseWriter interface { ...@@ -61,6 +61,7 @@ type ResponseWriter interface {
// WriteHeader (or Write) has no effect unless the modified // WriteHeader (or Write) has no effect unless the modified
// headers were declared as trailers by setting the // headers were declared as trailers by setting the
// "Trailer" header before the call to WriteHeader. // "Trailer" header before the call to WriteHeader.
// To suppress implicit response headers, set their value to nil.
Header() Header Header() Header
// Write writes the data to the connection as part of an HTTP reply. // Write writes the data to the connection as part of an HTTP reply.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment