@@ -742,7 +742,7 @@ func (t *http2Client) updateWindow(s *Stream, n uint32) {
742742}
743743
744744func (t * http2Client ) handleData (f * http2.DataFrame ) {
745- size := len ( f . Data ())
745+ size := f . Header (). Length
746746 if err := t .fc .onData (uint32 (size )); err != nil {
747747 t .notifyError (connectionErrorf (true , err , "%v" , err ))
748748 return
@@ -756,6 +756,11 @@ func (t *http2Client) handleData(f *http2.DataFrame) {
756756 return
757757 }
758758 if size > 0 {
759+ if f .Header ().Flags .Has (http2 .FlagDataPadded ) {
760+ if w := t .fc .onRead (uint32 (size ) - uint32 (len (f .Data ()))); w > 0 {
761+ t .controlBuf .put (& windowUpdate {0 , w })
762+ }
763+ }
759764 s .mu .Lock ()
760765 if s .state == streamDone {
761766 s .mu .Unlock ()
@@ -775,13 +780,20 @@ func (t *http2Client) handleData(f *http2.DataFrame) {
775780 t .controlBuf .put (& resetStream {s .id , http2 .ErrCodeFlowControl })
776781 return
777782 }
783+ if f .Header ().Flags .Has (http2 .FlagDataPadded ) {
784+ if w := s .fc .onRead (uint32 (size ) - uint32 (len (f .Data ()))); w > 0 {
785+ t .controlBuf .put (& windowUpdate {s .id , w })
786+ }
787+ }
778788 s .mu .Unlock ()
779789 // TODO(bradfitz, zhaoq): A copy is required here because there is no
780790 // guarantee f.Data() is consumed before the arrival of next frame.
781791 // Can this copy be eliminated?
782- data := make ([]byte , size )
783- copy (data , f .Data ())
784- s .write (recvMsg {data : data })
792+ if len (f .Data ()) > 0 {
793+ data := make ([]byte , len (f .Data ()))
794+ copy (data , f .Data ())
795+ s .write (recvMsg {data : data })
796+ }
785797 }
786798 // The server has closed the stream without sending trailers. Record that
787799 // the read direction is closed, and set the status appropriately.
0 commit comments