Commit f6be5216 authored by Russ Cox's avatar Russ Cox Committed by Brad Fitzpatrick

net/http: keep testing DetectContentType of empty body

Historically, DetectContentType has returned "text/plain; charset=utf-8"
for an empty body, there was a test for this, and there should continue
to be one.

CL 46631 changed the content-serving handlers to avoid setting any
Content-Type header when serving empty content. Even if that change
in behavior is correct, the CL is explicitly not changing DetectContentType,
so it must also not change DetectContentType's tests.

Change-Id: I7a19c9fabb43be47e349b40e729e49fceb3f2894
Reviewed-on: https://go-review.googlesource.com/82077
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 0b3b5113
......@@ -23,6 +23,7 @@ var sniffTests = []struct {
contentType string
}{
// Some nonsense.
{"Empty", []byte{}, "text/plain; charset=utf-8"},
{"Binary", []byte{1, 2, 3}, "application/octet-stream"},
{"HTML document #1", []byte(`<HtMl><bOdY>blah blah blah</body></html>`), "text/html; charset=utf-8"},
......@@ -98,8 +99,17 @@ func testServerContentType(t *testing.T, h2 bool) {
t.Errorf("%v: %v", tt.desc, err)
continue
}
if ct := resp.Header.Get("Content-Type"); ct != tt.contentType {
t.Errorf("%v: Content-Type = %q, want %q", tt.desc, ct, tt.contentType)
// DetectContentType is defined to return
// text/plain; charset=utf-8 for an empty body,
// but as of Go 1.10 the HTTP server has been changed
// to return no content-type at all for an empty body.
// Adjust the expectation here.
wantContentType := tt.contentType
if len(tt.data) == 0 {
wantContentType = ""
}
if ct := resp.Header.Get("Content-Type"); ct != wantContentType {
t.Errorf("%v: Content-Type = %q, want %q", tt.desc, ct, wantContentType)
}
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
......
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