From da2e91b33a0bca01d3036dc6539a5fa5f06e23c1 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Fri, 13 Apr 2018 07:50:44 +0200 Subject: [PATCH] Allow to write Http2UnkownFrame when using Http2FrameCodec / Http2MultiplexCodec (#7867) Motivation: We should allow to write Http2UnkownFrame to allow custom extensions. Modifications: Allow to write Http2UnkownFrame Add unit test Result: Fixes https://github.com/netty/netty/issues/7860. --- .../netty/handler/codec/http2/Http2FrameCodec.java | 4 ++++ .../handler/codec/http2/Http2FrameCodecTest.java | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2FrameCodec.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2FrameCodec.java index 046790974b..7b130bf6f3 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2FrameCodec.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2FrameCodec.java @@ -296,6 +296,10 @@ public class Http2FrameCodec extends Http2ConnectionHandler { encoder().writeSettings(ctx, ((Http2SettingsFrame) msg).settings(), promise); } else if (msg instanceof Http2GoAwayFrame) { writeGoAwayFrame(ctx, (Http2GoAwayFrame) msg, promise); + } else if (msg instanceof Http2UnknownFrame) { + Http2UnknownFrame unknownFrame = (Http2UnknownFrame) msg; + encoder().writeFrame(ctx, unknownFrame.frameType(), unknownFrame.stream().id(), + unknownFrame.flags(), unknownFrame.content(), promise); } else if (!(msg instanceof Http2Frame)) { ctx.write(msg, promise); } else { diff --git a/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2FrameCodecTest.java b/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2FrameCodecTest.java index 99468bcc33..7490701bb5 100644 --- a/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2FrameCodecTest.java +++ b/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2FrameCodecTest.java @@ -534,6 +534,20 @@ public class Http2FrameCodecTest { assertEquals(Integer.MAX_VALUE, localFlow.windowSize(connection.connectionStream())); } + @Test + public void writeUnknownFrame() { + final Http2FrameStream stream = frameCodec.newStream(); + + ByteBuf buffer = Unpooled.buffer().writeByte(1); + DefaultHttp2UnknownFrame unknownFrame = new DefaultHttp2UnknownFrame( + (byte) 20, new Http2Flags().ack(true), buffer); + unknownFrame.stream(stream); + channel.write(unknownFrame); + + verify(frameWriter).writeFrame(eq(http2HandlerCtx), eq(unknownFrame.frameType()), + eq(unknownFrame.stream().id()), eq(unknownFrame.flags()), eq(buffer), any(ChannelPromise.class)); + } + @Test public void sendSettingsFrame() { Http2Settings settings = new Http2Settings();