From 9c125eecb1df254bcf17bf1a6adf421602741ab0 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Tue, 16 Sep 2014 16:48:30 +0900 Subject: [PATCH] Add the encoder/decoder getter methods to HttpClientCodec Motivation: There's no way for a user to get the encoder and the decoder of an HttpClientCodec. The lack of such getter methods makes it impossible to remove the codec handlers from the pipeline correctly. For example, a user could add more than one HttpClientCodec to the pipeline, and then the user cannot easily decide which encoder and decoder to remove. Modifications: - Add encoder() and decoder() method to HttpClientCodec which returns HttpRequestEncoder and HttpResponseDecoder respectively - Also made the same changes to HttpServerCodec Result: A user can distinguish the handlers added by multiple HttpClientCodecs easily. --- .../netty/handler/codec/http/HttpClientCodec.java | 12 +++++++++++- .../netty/handler/codec/http/HttpServerCodec.java | 14 ++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpClientCodec.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpClientCodec.java index b2d0163562..e781a49d94 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpClientCodec.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpClientCodec.java @@ -97,7 +97,17 @@ public final class HttpClientCodec extends ChannelHandlerAppender implements ctx.pipeline().remove(Encoder.class); } - private Decoder decoder() { + /** + * Returns the encoder of this codec. + */ + public HttpRequestEncoder encoder() { + return handlerAt(1); + } + + /** + * Returns the decoder of this codec. + */ + public HttpResponseDecoder decoder() { return handlerAt(0); } diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpServerCodec.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpServerCodec.java index 8a56710b28..768d63c532 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpServerCodec.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpServerCodec.java @@ -64,4 +64,18 @@ public final class HttpServerCodec extends ChannelHandlerAppender implements ctx.pipeline().remove(HttpRequestDecoder.class); ctx.pipeline().remove(HttpResponseEncoder.class); } + + /** + * Returns the encoder of this codec. + */ + public HttpResponseEncoder encoder() { + return handlerAt(1); + } + + /** + * Returns the decoder of this codec. + */ + public HttpRequestDecoder decoder() { + return handlerAt(0); + } }