@@ -4098,3 +4098,62 @@ func TestContentEncodingNoSniffing(t *testing.T) {
4098
4098
})
4099
4099
}
4100
4100
}
4101
+
4102
+ func TestServerWindowUpdateOnBodyClose (t * testing.T ) {
4103
+ const content = "12345678"
4104
+ blockCh := make (chan bool )
4105
+ errc := make (chan error , 1 )
4106
+ st := newServerTester (t , func (w http.ResponseWriter , r * http.Request ) {
4107
+ buf := make ([]byte , 4 )
4108
+ n , err := io .ReadFull (r .Body , buf )
4109
+ if err != nil {
4110
+ errc <- err
4111
+ return
4112
+ }
4113
+ if n != len (buf ) {
4114
+ errc <- fmt .Errorf ("too few bytes read: %d" , n )
4115
+ return
4116
+ }
4117
+ blockCh <- true
4118
+ <- blockCh
4119
+ errc <- nil
4120
+ })
4121
+ defer st .Close ()
4122
+
4123
+ st .greet ()
4124
+ st .writeHeaders (HeadersFrameParam {
4125
+ StreamID : 1 , // clients send odd numbers
4126
+ BlockFragment : st .encodeHeader (
4127
+ ":method" , "POST" ,
4128
+ "content-length" , strconv .Itoa (len (content )),
4129
+ ),
4130
+ EndStream : false , // to say DATA frames are coming
4131
+ EndHeaders : true ,
4132
+ })
4133
+ st .writeData (1 , false , []byte (content [:5 ]))
4134
+ <- blockCh
4135
+ st .stream (1 ).body .CloseWithError (io .EOF )
4136
+ st .writeData (1 , false , []byte (content [5 :]))
4137
+ blockCh <- true
4138
+
4139
+ increments := len (content )
4140
+ for {
4141
+ f , err := st .readFrame ()
4142
+ if err == io .EOF {
4143
+ break
4144
+ }
4145
+ if err != nil {
4146
+ t .Fatal (err )
4147
+ }
4148
+ if wu , ok := f .(* WindowUpdateFrame ); ok && wu .StreamID == 0 {
4149
+ increments -= int (wu .Increment )
4150
+ if increments == 0 {
4151
+ break
4152
+ }
4153
+ }
4154
+ }
4155
+
4156
+ if err := <- errc ; err != nil {
4157
+ t .Error (err )
4158
+ }
4159
+ }
0 commit comments