6060import io .netty .channel .ChannelFutureListener ;
6161import io .netty .channel .ChannelHandlerContext ;
6262import io .netty .channel .ChannelPromise ;
63+ import io .netty .handler .codec .http .HttpHeaderNames ;
6364import io .netty .handler .codec .http2 .DecoratingHttp2ConnectionEncoder ;
6465import io .netty .handler .codec .http2 .DecoratingHttp2FrameWriter ;
6566import io .netty .handler .codec .http2 .DefaultHttp2Connection ;
7071import io .netty .handler .codec .http2 .DefaultHttp2Headers ;
7172import io .netty .handler .codec .http2 .DefaultHttp2LocalFlowController ;
7273import io .netty .handler .codec .http2 .DefaultHttp2RemoteFlowController ;
74+ import io .netty .handler .codec .http2 .EmptyHttp2Headers ;
7375import io .netty .handler .codec .http2 .Http2Connection ;
7476import io .netty .handler .codec .http2 .Http2ConnectionAdapter ;
7577import io .netty .handler .codec .http2 .Http2ConnectionDecoder ;
@@ -480,8 +482,10 @@ private void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers
480482 }
481483
482484 if (!HTTP_METHOD .contentEquals (headers .method ())) {
485+ Http2Headers extraHeaders = new DefaultHttp2Headers ();
486+ extraHeaders .add (HttpHeaderNames .ALLOW , HTTP_METHOD );
483487 respondWithHttpError (ctx , streamId , 405 , Status .Code .INTERNAL ,
484- String .format ("Method '%s' is not supported" , headers .method ()));
488+ String .format ("Method '%s' is not supported" , headers .method ()), extraHeaders );
485489 return ;
486490 }
487491
@@ -868,7 +872,13 @@ public boolean visit(Http2Stream stream) throws Http2Exception {
868872 }
869873
870874 private void respondWithHttpError (
871- ChannelHandlerContext ctx , int streamId , int code , Status .Code statusCode , String msg ) {
875+ ChannelHandlerContext ctx , int streamId , int code , Status .Code statusCode , String msg ) {
876+ respondWithHttpError (ctx , streamId , code , statusCode , msg , EmptyHttp2Headers .INSTANCE );
877+ }
878+
879+ private void respondWithHttpError (
880+ ChannelHandlerContext ctx , int streamId , int code , Status .Code statusCode , String msg ,
881+ Http2Headers extraHeaders ) {
872882 Metadata metadata = new Metadata ();
873883 metadata .put (InternalStatus .CODE_KEY , statusCode .toStatus ());
874884 metadata .put (InternalStatus .MESSAGE_KEY , msg );
@@ -880,6 +890,7 @@ private void respondWithHttpError(
880890 for (int i = 0 ; i < serialized .length ; i += 2 ) {
881891 headers .add (new AsciiString (serialized [i ], false ), new AsciiString (serialized [i + 1 ], false ));
882892 }
893+ headers .add (extraHeaders );
883894 encoder ().writeHeaders (ctx , streamId , headers , 0 , false , ctx .newPromise ());
884895 ByteBuf msgBuf = ByteBufUtil .writeUtf8 (ctx .alloc (), msg );
885896 encoder ().writeData (ctx , streamId , msgBuf , 0 , true , ctx .newPromise ());
0 commit comments