@@ -809,6 +809,9 @@ func TestServer_Request_Post_Body_ContentLength_TooSmall(t *testing.T) {
809
809
EndHeaders : true ,
810
810
})
811
811
st .writeData (1 , true , []byte ("12345" ))
812
+ // Return flow control bytes back, since the data handler closed
813
+ // the stream.
814
+ st .wantWindowUpdate (0 , 5 )
812
815
})
813
816
}
814
817
@@ -1244,41 +1247,6 @@ func TestServer_Handler_Sends_WindowUpdate(t *testing.T) {
1244
1247
1245
1248
st .greet ()
1246
1249
1247
- st .writeHeaders (HeadersFrameParam {
1248
- StreamID : 1 , // clients send odd numbers
1249
- BlockFragment : st .encodeHeader (":method" , "POST" ),
1250
- EndStream : false , // data coming
1251
- EndHeaders : true ,
1252
- })
1253
- updateSize := 1 << 20 / 2 // the conn & stream size before a WindowUpdate
1254
- st .writeData (1 , false , bytes .Repeat ([]byte ("a" ), updateSize - 10 ))
1255
- st .writeData (1 , false , bytes .Repeat ([]byte ("b" ), 10 ))
1256
- puppet .do (readBodyHandler (t , strings .Repeat ("a" , updateSize - 10 )))
1257
- puppet .do (readBodyHandler (t , strings .Repeat ("b" , 10 )))
1258
-
1259
- st .wantWindowUpdate (0 , uint32 (updateSize ))
1260
- st .wantWindowUpdate (1 , uint32 (updateSize ))
1261
-
1262
- st .writeData (1 , false , bytes .Repeat ([]byte ("a" ), updateSize - 10 ))
1263
- st .writeData (1 , true , bytes .Repeat ([]byte ("c" ), 15 )) // END_STREAM here
1264
- puppet .do (readBodyHandler (t , strings .Repeat ("a" , updateSize - 10 )))
1265
- puppet .do (readBodyHandler (t , strings .Repeat ("c" , 15 )))
1266
-
1267
- st .wantWindowUpdate (0 , uint32 (updateSize + 5 ))
1268
- }
1269
-
1270
- func TestServer_Handler_Sends_WindowUpdate_SmallStream (t * testing.T ) {
1271
- puppet := newHandlerPuppet ()
1272
- st := newServerTester (t , func (w http.ResponseWriter , r * http.Request ) {
1273
- puppet .act (w , r )
1274
- }, func (s * Server ) {
1275
- s .MaxUploadBufferPerStream = 6
1276
- })
1277
- defer st .Close ()
1278
- defer puppet .done ()
1279
-
1280
- st .greet ()
1281
-
1282
1250
st .writeHeaders (HeadersFrameParam {
1283
1251
StreamID : 1 , // clients send odd numbers
1284
1252
BlockFragment : st .encodeHeader (":method" , "POST" ),
@@ -1287,14 +1255,18 @@ func TestServer_Handler_Sends_WindowUpdate_SmallStream(t *testing.T) {
1287
1255
})
1288
1256
st .writeData (1 , false , []byte ("abcdef" ))
1289
1257
puppet .do (readBodyHandler (t , "abc" ))
1290
- puppet . do ( readBodyHandler ( t , "d" ) )
1291
- puppet . do ( readBodyHandler ( t , "ef" ) )
1258
+ st . wantWindowUpdate ( 0 , 3 )
1259
+ st . wantWindowUpdate ( 1 , 3 )
1292
1260
1293
- st .wantWindowUpdate (1 , 6 )
1261
+ puppet .do (readBodyHandler (t , "def" ))
1262
+ st .wantWindowUpdate (0 , 3 )
1263
+ st .wantWindowUpdate (1 , 3 )
1294
1264
1295
1265
st .writeData (1 , true , []byte ("ghijkl" )) // END_STREAM here
1296
1266
puppet .do (readBodyHandler (t , "ghi" ))
1297
1267
puppet .do (readBodyHandler (t , "jkl" ))
1268
+ st .wantWindowUpdate (0 , 3 )
1269
+ st .wantWindowUpdate (0 , 3 ) // no more stream-level, since END_STREAM
1298
1270
}
1299
1271
1300
1272
// the version of the TestServer_Handler_Sends_WindowUpdate with padding.
@@ -1323,45 +1295,12 @@ func TestServer_Handler_Sends_WindowUpdate_Padding(t *testing.T) {
1323
1295
st .wantWindowUpdate (1 , 5 )
1324
1296
1325
1297
puppet .do (readBodyHandler (t , "abc" ))
1326
- puppet .do (readBodyHandler (t , "def" ))
1327
- }
1328
-
1329
- // This is a regression test to make sure the correct window increment size is
1330
- // calculated for a stream.
1331
- // See https://go.dev/issue/56315#issuecomment-1287642591.
1332
- func TestServer_Handler_Sends_WindowUpdate_IncrementSize (t * testing.T ) {
1333
- maxSizePerConn := initialWindowSize * 2
1334
- maxSizePerStream := maxSizePerConn * 2 + 100
1298
+ st .wantWindowUpdate (0 , 3 )
1299
+ st .wantWindowUpdate (1 , 3 )
1335
1300
1336
- puppet := newHandlerPuppet ()
1337
- st := newServerTester (t , func (w http.ResponseWriter , r * http.Request ) {
1338
- puppet .act (w , r )
1339
- }, func (s * Server ) {
1340
- s .MaxUploadBufferPerConnection = int32 (maxSizePerConn )
1341
- s .MaxUploadBufferPerStream = int32 (maxSizePerStream )
1342
- })
1343
- defer st .Close ()
1344
- defer puppet .done ()
1345
-
1346
- st .greet ()
1347
-
1348
- st .writeHeaders (HeadersFrameParam {
1349
- StreamID : 1 ,
1350
- BlockFragment : st .encodeHeader (":method" , "POST" ),
1351
- EndStream : false ,
1352
- EndHeaders : true ,
1353
- })
1354
-
1355
- st .writeData (1 , false , bytes .Repeat ([]byte ("a" ), maxSizePerConn / 2 ))
1356
- puppet .do (readBodyHandler (t , strings .Repeat ("a" , maxSizePerConn / 2 )))
1357
- st .wantWindowUpdate (0 , uint32 (maxSizePerConn / 2 ))
1358
-
1359
- st .writeData (1 , false , bytes .Repeat ([]byte ("b" ), maxSizePerConn / 2 + 100 ))
1360
- puppet .do (readBodyHandler (t , strings .Repeat ("b" , maxSizePerConn / 2 + 100 )))
1361
- st .wantWindowUpdate (0 , uint32 (maxSizePerConn / 2 + 100 ))
1362
- st .wantWindowUpdate (1 , uint32 (maxSizePerConn + 100 ))
1363
-
1364
- st .writeData (1 , true , nil ) // END_STREAM here
1301
+ puppet .do (readBodyHandler (t , "def" ))
1302
+ st .wantWindowUpdate (0 , 3 )
1303
+ st .wantWindowUpdate (1 , 3 )
1365
1304
}
1366
1305
1367
1306
func TestServer_Send_GoAway_After_Bogus_WindowUpdate (t * testing.T ) {
@@ -2357,6 +2296,8 @@ func TestServer_Response_Automatic100Continue(t *testing.T) {
2357
2296
// gigantic and/or sensitive "foo" payload now.
2358
2297
st .writeData (1 , true , []byte (msg ))
2359
2298
2299
+ st .wantWindowUpdate (0 , uint32 (len (msg )))
2300
+
2360
2301
hf = st .wantHeaders ()
2361
2302
if hf .StreamEnded () {
2362
2303
t .Fatal ("expected data to follow" )
@@ -2544,6 +2485,9 @@ func TestServer_NoCrash_HandlerClose_Then_ClientClose(t *testing.T) {
2544
2485
// it did before.
2545
2486
st .writeData (1 , true , []byte ("foo" ))
2546
2487
2488
+ // Get our flow control bytes back, since the handler didn't get them.
2489
+ st .wantWindowUpdate (0 , uint32 (len ("foo" )))
2490
+
2547
2491
// Sent after a peer sends data anyway (admittedly the
2548
2492
// previous RST_STREAM might've still been in-flight),
2549
2493
// but they'll get the more friendly 'cancel' code
@@ -3986,6 +3930,7 @@ func TestServer_Rejects_TooSmall(t *testing.T) {
3986
3930
EndHeaders : true ,
3987
3931
})
3988
3932
st .writeData (1 , true , []byte ("12345" ))
3933
+ st .wantWindowUpdate (0 , 5 )
3989
3934
st .wantRSTStream (1 , ErrCodeProtocol )
3990
3935
})
3991
3936
}
@@ -4312,6 +4257,7 @@ func TestServerWindowUpdateOnBodyClose(t *testing.T) {
4312
4257
st .writeData (1 , false , []byte (content [5 :]))
4313
4258
blockCh <- true
4314
4259
4260
+ increments := len (content )
4315
4261
for {
4316
4262
f , err := st .readFrame ()
4317
4263
if err == io .EOF {
@@ -4320,12 +4266,10 @@ func TestServerWindowUpdateOnBodyClose(t *testing.T) {
4320
4266
if err != nil {
4321
4267
t .Fatal (err )
4322
4268
}
4323
- if rs , ok := f .(* RSTStreamFrame ); ok && rs .StreamID == 1 {
4324
- break
4325
- }
4326
4269
if wu , ok := f .(* WindowUpdateFrame ); ok && wu .StreamID == 0 {
4327
- if e , a := uint32 (3 ), wu .Increment ; e != a {
4328
- t .Errorf ("Increment=%d, want %d" , a , e )
4270
+ increments -= int (wu .Increment )
4271
+ if increments == 0 {
4272
+ break
4329
4273
}
4330
4274
}
4331
4275
}
@@ -4468,22 +4412,22 @@ func TestServerSendsEarlyHints(t *testing.T) {
4468
4412
4469
4413
func TestProtocolErrorAfterGoAway (t * testing.T ) {
4470
4414
st := newServerTester (t , func (w http.ResponseWriter , r * http.Request ) {
4471
- w .WriteHeader (200 )
4472
- w .(http.Flusher ).Flush ()
4473
4415
io .Copy (io .Discard , r .Body )
4474
4416
})
4475
4417
defer st .Close ()
4476
4418
4477
4419
st .greet ()
4420
+ content := "some content"
4478
4421
st .writeHeaders (HeadersFrameParam {
4479
4422
StreamID : 1 ,
4480
4423
BlockFragment : st .encodeHeader (
4481
4424
":method" , "POST" ,
4482
- "content-length" , "1" ,
4425
+ "content-length" , strconv . Itoa ( len ( content )) ,
4483
4426
),
4484
4427
EndStream : false ,
4485
4428
EndHeaders : true ,
4486
4429
})
4430
+ st .writeData (1 , false , []byte (content [:5 ]))
4487
4431
4488
4432
_ , err := st .readFrame ()
4489
4433
if err != nil {
0 commit comments