reqHeader: map[string]string{
"If-Match": `"B"`,
},
- wantStatus: 412,
- wantContentType: "text/plain; charset=utf-8",
+ wantStatus: 412,
},
"ifmatch_fails_on_weak_etag": {
file: "testdata/style.css",
reqHeader: map[string]string{
"If-Match": `W/"A"`,
},
- wantStatus: 412,
- wantContentType: "text/plain; charset=utf-8",
+ wantStatus: 412,
},
"if_unmodified_since_true": {
file: "testdata/style.css",
reqHeader: map[string]string{
"If-Unmodified-Since": htmlModTime.Add(-2 * time.Second).UTC().Format(TimeFormat),
},
- wantStatus: 412,
- wantContentType: "text/plain; charset=utf-8",
- wantLastMod: htmlModTime.UTC().Format(TimeFormat),
+ wantStatus: 412,
+ wantLastMod: htmlModTime.UTC().Format(TimeFormat),
},
}
for testName, tt := range tests {
clen = strconv.Itoa(len(p))
}
_, hasContentType := rws.snapHeader["Content-Type"]
- if !hasContentType && http2bodyAllowedForStatus(rws.status) {
+ if !hasContentType && http2bodyAllowedForStatus(rws.status) && len(p) > 0 {
ctype = DetectContentType(p)
}
var date string
handler: func(rw ResponseWriter, r *Request) {
},
check: func(got string) error {
- if !strings.Contains(got, "Content-Type: text/plain") {
- return errors.New("wrong content-type; want text/plain")
- }
if !strings.Contains(got, "Content-Length: 0") {
return errors.New("want 0 content-length")
}
if bodyAllowedForStatus(code) {
// If no content type, apply sniffing algorithm to body.
_, haveType := header["Content-Type"]
- if !haveType && !hasTE {
+ if !haveType && !hasTE && len(p) > 0 {
setHeader.contentType = DetectContentType(p)
}
} else {
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"},