@@ -121,15 +121,17 @@ func testChunkedResponseHeaders(t *testing.T, h2 bool) {
121
121
}
122
122
}
123
123
124
+ type reqFunc func (c * Client , url string ) (* Response , error )
125
+
124
126
// h12Compare is a test that compares HTTP/1 and HTTP/2 behavior
125
127
// against each other.
126
128
type h12Compare struct {
127
- Handler func (ResponseWriter , * Request ) // required
128
- ReqFunc func ( c * Client , url string ) ( * Response , error ) // optional
129
- CheckResponse func (proto string , res * Response ) // optional
129
+ Handler func (ResponseWriter , * Request ) // required
130
+ ReqFunc reqFunc // optional
131
+ CheckResponse func (proto string , res * Response ) // optional
130
132
}
131
133
132
- func (tt h12Compare ) reqFunc () func ( c * Client , url string ) ( * Response , error ) {
134
+ func (tt h12Compare ) reqFunc () reqFunc {
133
135
if tt .ReqFunc == nil {
134
136
return (* Client ).Get
135
137
}
@@ -213,6 +215,36 @@ func (tt h12Compare) normalizeRes(t *testing.T, res *Response, wantProto string)
213
215
}
214
216
}
215
217
218
+ // Issue 13532
219
+ func TestH12_HeadContentLengthNoBody (t * testing.T ) {
220
+ h12Compare {
221
+ ReqFunc : (* Client ).Head ,
222
+ Handler : func (w ResponseWriter , r * Request ) {
223
+ },
224
+ }.run (t )
225
+ }
226
+
227
+ func TestH12_HeadContentLengthSmallBody (t * testing.T ) {
228
+ h12Compare {
229
+ ReqFunc : (* Client ).Head ,
230
+ Handler : func (w ResponseWriter , r * Request ) {
231
+ io .WriteString (w , "small" )
232
+ },
233
+ }.run (t )
234
+ }
235
+
236
+ func TestH12_HeadContentLengthLargeBody (t * testing.T ) {
237
+ h12Compare {
238
+ ReqFunc : (* Client ).Head ,
239
+ Handler : func (w ResponseWriter , r * Request ) {
240
+ chunk := strings .Repeat ("x" , 512 << 10 )
241
+ for i := 0 ; i < 10 ; i ++ {
242
+ io .WriteString (w , chunk )
243
+ }
244
+ },
245
+ }.run (t )
246
+ }
247
+
216
248
func TestH12_200NoBody (t * testing.T ) {
217
249
h12Compare {Handler : func (w ResponseWriter , r * Request ) {}}.run (t )
218
250
}
@@ -371,3 +403,12 @@ func test304Responses(t *testing.T, h2 bool) {
371
403
t .Errorf ("got unexpected body %q" , string (body ))
372
404
}
373
405
}
406
+
407
+ func TestH12_ServerEmptyContentLength (t * testing.T ) {
408
+ h12Compare {
409
+ Handler : func (w ResponseWriter , r * Request ) {
410
+ w .Header ()["Content-Type" ] = []string {"" }
411
+ io .WriteString (w , "<html><body>hi</body></html>" )
412
+ },
413
+ }.run (t )
414
+ }
0 commit comments