mirror of https://github.com/golang/go.git
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/9412 Reviewed-by: David Crawshaw <crawshaw@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
d3bd6b6ae7
commit
5ed44e9d4d
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Reference in New Issue