lue("i")) tt := sniffTests[i] n, err := w.Write(tt.data) if n != len(tt.data) || err != nil { log.Fatalf("%v: Write(%q) = %v, %v want %d, nil", tt.desc, tt.data, n, err, len(tt.data)) } })) defer cst.close() for i, tt := range sniffTests { resp, err := cst.c.Get(cst.ts.URL + "/?i=" + strconv.Itoa(i)) if err != nil { t.Errorf("%v: %v", tt.desc, err) continue } // 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 := io.ReadAll(resp.Body) if err != nil { t.Errorf("%v: reading body: %v", tt.desc, err) } else if !bytes.Equal(data, tt.data) { t.Errorf("%v: data is %q, want %q", tt.desc, data, tt.data) } resp.Body.Close() } } // 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) { run(t, testServerIssue5953) } func testServerIssue5953(t *testing.T, mode testMode) { cst := newClientServerTest(t, mode, HandlerFunc(func(w ResponseWriter, r *Request) { w.Header()["Content-Type"] = []string{""} fmt.Fprintf(w, "
hi