From e4d9a17ad9e0ccaa5f06a2ca0fb46dc37e7fa68e Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Fri, 16 Aug 2019 08:16:15 +0200 Subject: [PATCH] Http2EmptyDataFrameConnectionDecoder.frameListener() should return unwrapped Http2FrameListener (#9467) Motivation: As we decorate the Http2FrameListener under the covers we should ensure the user can still access the original Http2FrameListener. Modifications: - Unwrap the Http2FrameListener in frameListener() - Add unit test Result: Less suprises for users. --- .../Http2EmptyDataFrameConnectionDecoder.java | 17 ++++++++++++++++- ...ttp2EmptyDataFrameConnectionDecoderTest.java | 4 +++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2EmptyDataFrameConnectionDecoder.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2EmptyDataFrameConnectionDecoder.java index 93957c7909..4f0e15510a 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2EmptyDataFrameConnectionDecoder.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2EmptyDataFrameConnectionDecoder.java @@ -24,7 +24,7 @@ final class Http2EmptyDataFrameConnectionDecoder extends DecoratingHttp2Connecti private final int maxConsecutiveEmptyFrames; - Http2EmptyDataFrameConnectionDecoder(Http2ConnectionDecoder delegate, int maxConsecutiveEmptyFrames) { + Http2EmptyDataFrameConnectionDecoder(Http2ConnectionDecoder delegate, int maxConsecutiveEmptyFrames) { super(delegate); this.maxConsecutiveEmptyFrames = ObjectUtil.checkPositive( maxConsecutiveEmptyFrames, "maxConsecutiveEmptyFrames"); @@ -38,4 +38,19 @@ final class Http2EmptyDataFrameConnectionDecoder extends DecoratingHttp2Connecti super.frameListener(null); } } + + @Override + public Http2FrameListener frameListener() { + Http2FrameListener frameListener = frameListener0(); + // Unwrap the original Http2FrameListener as we add this decoder under the hood. + if (frameListener instanceof Http2EmptyDataFrameListener) { + return ((Http2EmptyDataFrameListener) frameListener).listener; + } + return frameListener; + } + + // Package-private for testing + Http2FrameListener frameListener0() { + return super.frameListener(); + } } diff --git a/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2EmptyDataFrameConnectionDecoderTest.java b/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2EmptyDataFrameConnectionDecoderTest.java index 2241c23f6d..346a09a863 100644 --- a/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2EmptyDataFrameConnectionDecoderTest.java +++ b/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2EmptyDataFrameConnectionDecoderTest.java @@ -44,7 +44,9 @@ public class Http2EmptyDataFrameConnectionDecoderTest { decoder.frameListener(listener); verify(delegate).frameListener(listenerArgumentCaptor.capture()); - assertThat(decoder.frameListener(), CoreMatchers.instanceOf(Http2EmptyDataFrameListener.class)); + assertThat(decoder.frameListener(), + CoreMatchers.not(CoreMatchers.instanceOf(Http2EmptyDataFrameListener.class))); + assertThat(decoder.frameListener0(), CoreMatchers.instanceOf(Http2EmptyDataFrameListener.class)); } @Test