@@ -480,11 +480,12 @@ func (t *http2Server) operateHeaders(ctx context.Context, frame *http2.MetaHeade
480480 t .logger .Infof ("Aborting the stream early: %v" , errMsg )
481481 }
482482 t .controlBuf .put (& earlyAbortStream {
483- httpStatus : http .StatusBadRequest ,
484- streamID : streamID ,
485- contentSubtype : s .contentSubtype ,
486- status : status .New (codes .Internal , errMsg ),
487- rst : ! frame .StreamEnded (),
483+ httpStatus : http .StatusBadRequest ,
484+ streamID : streamID ,
485+ contentSubtype : s .contentSubtype ,
486+ status : status .New (codes .Internal , errMsg ),
487+ rst : ! frame .StreamEnded (),
488+ maxSendHeaderListSize : t .maxSendHeaderListSize ,
488489 })
489490 return nil
490491 }
@@ -500,21 +501,23 @@ func (t *http2Server) operateHeaders(ctx context.Context, frame *http2.MetaHeade
500501 }
501502 if ! isGRPC {
502503 t .controlBuf .put (& earlyAbortStream {
503- httpStatus : http .StatusUnsupportedMediaType ,
504- streamID : streamID ,
505- contentSubtype : s .contentSubtype ,
506- status : status .Newf (codes .InvalidArgument , "invalid gRPC request content-type %q" , contentType ),
507- rst : ! frame .StreamEnded (),
504+ httpStatus : http .StatusUnsupportedMediaType ,
505+ streamID : streamID ,
506+ contentSubtype : s .contentSubtype ,
507+ status : status .Newf (codes .InvalidArgument , "invalid gRPC request content-type %q" , contentType ),
508+ rst : ! frame .StreamEnded (),
509+ maxSendHeaderListSize : t .maxSendHeaderListSize ,
508510 })
509511 return nil
510512 }
511513 if headerError != nil {
512514 t .controlBuf .put (& earlyAbortStream {
513- httpStatus : http .StatusBadRequest ,
514- streamID : streamID ,
515- contentSubtype : s .contentSubtype ,
516- status : headerError ,
517- rst : ! frame .StreamEnded (),
515+ httpStatus : http .StatusBadRequest ,
516+ streamID : streamID ,
517+ contentSubtype : s .contentSubtype ,
518+ status : headerError ,
519+ rst : ! frame .StreamEnded (),
520+ maxSendHeaderListSize : t .maxSendHeaderListSize ,
518521 })
519522 return nil
520523 }
@@ -570,11 +573,12 @@ func (t *http2Server) operateHeaders(ctx context.Context, frame *http2.MetaHeade
570573 t .logger .Infof ("Aborting the stream early: %v" , errMsg )
571574 }
572575 t .controlBuf .put (& earlyAbortStream {
573- httpStatus : http .StatusMethodNotAllowed ,
574- streamID : streamID ,
575- contentSubtype : s .contentSubtype ,
576- status : status .New (codes .Internal , errMsg ),
577- rst : ! frame .StreamEnded (),
576+ httpStatus : http .StatusMethodNotAllowed ,
577+ streamID : streamID ,
578+ contentSubtype : s .contentSubtype ,
579+ status : status .New (codes .Internal , errMsg ),
580+ rst : ! frame .StreamEnded (),
581+ maxSendHeaderListSize : t .maxSendHeaderListSize ,
578582 })
579583 s .cancel ()
580584 return nil
@@ -591,11 +595,12 @@ func (t *http2Server) operateHeaders(ctx context.Context, frame *http2.MetaHeade
591595 stat = status .New (codes .PermissionDenied , err .Error ())
592596 }
593597 t .controlBuf .put (& earlyAbortStream {
594- httpStatus : http .StatusOK ,
595- streamID : s .id ,
596- contentSubtype : s .contentSubtype ,
597- status : stat ,
598- rst : ! frame .StreamEnded (),
598+ httpStatus : http .StatusOK ,
599+ streamID : s .id ,
600+ contentSubtype : s .contentSubtype ,
601+ status : stat ,
602+ rst : ! frame .StreamEnded (),
603+ maxSendHeaderListSize : t .maxSendHeaderListSize ,
599604 })
600605 return nil
601606 }
@@ -605,11 +610,12 @@ func (t *http2Server) operateHeaders(ctx context.Context, frame *http2.MetaHeade
605610 t .mu .Unlock ()
606611 // Early abort in case the timeout was zero or so low it already fired.
607612 t .controlBuf .put (& earlyAbortStream {
608- httpStatus : http .StatusOK ,
609- streamID : s .id ,
610- contentSubtype : s .contentSubtype ,
611- status : status .New (codes .DeadlineExceeded , context .DeadlineExceeded .Error ()),
612- rst : ! frame .StreamEnded (),
613+ httpStatus : http .StatusOK ,
614+ streamID : s .id ,
615+ contentSubtype : s .contentSubtype ,
616+ status : status .New (codes .DeadlineExceeded , context .DeadlineExceeded .Error ()),
617+ rst : ! frame .StreamEnded (),
618+ maxSendHeaderListSize : t .maxSendHeaderListSize ,
613619 })
614620 return nil
615621 }
@@ -969,23 +975,32 @@ func appendHeaderFieldsFromMD(headerFields []hpack.HeaderField, md metadata.MD)
969975 return headerFields
970976}
971977
972- func (t * http2Server ) checkForHeaderListSize (it any ) bool {
973- if t .maxSendHeaderListSize == nil {
978+ // checkForHeaderListSize checks if the header list size exceeds the limit set
979+ // by the peer. It returns false if the limit is exceeded.
980+ func checkForHeaderListSize (hf []hpack.HeaderField , maxSendHeaderListSize * uint32 ) bool {
981+ if maxSendHeaderListSize == nil {
974982 return true
975983 }
976- hdrFrame := it .(* headerFrame )
977984 var sz int64
978- for _ , f := range hdrFrame .hf {
979- if sz += int64 (f .Size ()); sz > int64 (* t .maxSendHeaderListSize ) {
980- if t .logger .V (logLevel ) {
981- t .logger .Infof ("Header list size to send violates the maximum size (%d bytes) set by client" , * t .maxSendHeaderListSize )
982- }
985+ for _ , f := range hf {
986+ if sz += int64 (f .Size ()); sz > int64 (* maxSendHeaderListSize ) {
983987 return false
984988 }
985989 }
986990 return true
987991}
988992
993+ func (t * http2Server ) checkForHeaderListSize (it any ) bool {
994+ hdrFrame := it .(* headerFrame )
995+ if ! checkForHeaderListSize (hdrFrame .hf , t .maxSendHeaderListSize ) {
996+ if t .logger .V (logLevel ) {
997+ t .logger .Infof ("Header list size to send violates the maximum size (%d bytes) set by client" , * t .maxSendHeaderListSize )
998+ }
999+ return false
1000+ }
1001+ return true
1002+ }
1003+
9891004func (t * http2Server ) streamContextErr (s * ServerStream ) error {
9901005 select {
9911006 case <- t .done :
0 commit comments