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.
This commit is contained in:
Trustin Lee 2014-09-16 16:48:30 +09:00
parent 8f8a06ab0a
commit 9c125eecb1
2 changed files with 25 additions and 1 deletions

View File

@ -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);
}

View File

@ -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);
}
}