}
}
+type reqFunc func(c *Client, url string) (*Response, error)
+
// h12Compare is a test that compares HTTP/1 and HTTP/2 behavior
// against each other.
type h12Compare struct {
- Handler func(ResponseWriter, *Request) // required
- ReqFunc func(c *Client, url string) (*Response, error) // optional
- CheckResponse func(proto string, res *Response) // optional
+ Handler func(ResponseWriter, *Request) // required
+ ReqFunc reqFunc // optional
+ CheckResponse func(proto string, res *Response) // optional
}
-func (tt h12Compare) reqFunc() func(c *Client, url string) (*Response, error) {
+func (tt h12Compare) reqFunc() reqFunc {
if tt.ReqFunc == nil {
return (*Client).Get
}
}
}
+// Issue 13532
+func TestH12_HeadContentLengthNoBody(t *testing.T) {
+ h12Compare{
+ ReqFunc: (*Client).Head,
+ Handler: func(w ResponseWriter, r *Request) {
+ },
+ }.run(t)
+}
+
+func TestH12_HeadContentLengthSmallBody(t *testing.T) {
+ h12Compare{
+ ReqFunc: (*Client).Head,
+ Handler: func(w ResponseWriter, r *Request) {
+ io.WriteString(w, "small")
+ },
+ }.run(t)
+}
+
+func TestH12_HeadContentLengthLargeBody(t *testing.T) {
+ h12Compare{
+ ReqFunc: (*Client).Head,
+ Handler: func(w ResponseWriter, r *Request) {
+ chunk := strings.Repeat("x", 512<<10)
+ for i := 0; i < 10; i++ {
+ io.WriteString(w, chunk)
+ }
+ },
+ }.run(t)
+}
+
func TestH12_200NoBody(t *testing.T) {
h12Compare{Handler: func(w ResponseWriter, r *Request) {}}.run(t)
}
t.Errorf("got unexpected body %q", string(body))
}
}
+
+func TestH12_ServerEmptyContentLength(t *testing.T) {
+ h12Compare{
+ Handler: func(w ResponseWriter, r *Request) {
+ w.Header()["Content-Type"] = []string{""}
+ io.WriteString(w, "<html><body>hi</body></html>")
+ },
+ }.run(t)
+}
clen = ""
}
}
- if clen == "" && rws.handlerDone && http2bodyAllowedForStatus(rws.status) {
+ if clen == "" && rws.handlerDone && http2bodyAllowedForStatus(rws.status) && (len(p) > 0 || !isHeadResp) {
clen = strconv.Itoa(len(p))
}
- if rws.snapHeader.Get("Content-Type") == "" && http2bodyAllowedForStatus(rws.status) {
+ _, hasContentType := rws.snapHeader["Content-Type"]
+ if !hasContentType && http2bodyAllowedForStatus(rws.status) {
ctype = DetectContentType(p)
}
var date string