public abstract class HttpContentDecoder extends MessageToMessageDecoder<HttpObject>
HttpRequest
and HttpContent
.
The original content is replaced with the new content decoded by the
EmbeddedChannel
, which is created by newContentDecoder(String)
.
Once decoding is finished, the value of the 'Content-Encoding'
header is set to the target content encoding, as returned by getTargetContentEncoding(String)
.
Also, the 'Content-Length' header is updated to the length of the
decoded content. If the content encoding of the original is not supported
by the decoder, newContentDecoder(String)
should return null
so that no decoding occurs (i.e. pass-through).
Please note that this is an abstract class. You have to extend this class
and implement newContentDecoder(String)
properly to make this class
functional. For example, refer to the source code of HttpContentDecompressor
.
This handler must be placed after HttpObjectDecoder
in the pipeline
so that this handler can intercept HTTP requests after HttpObjectDecoder
converts ByteBuf
s into HTTP requests.
ChannelHandler.Sharable
限定符和类型 | 字段和说明 |
---|---|
protected ChannelHandlerContext |
ctx |
构造器和说明 |
---|
HttpContentDecoder() |
限定符和类型 | 方法和说明 |
---|---|
void |
channelInactive(ChannelHandlerContext ctx)
Calls
ChannelHandlerContext.fireChannelInactive() to forward
to the next ChannelInboundHandler in the ChannelPipeline . |
void |
channelReadComplete(ChannelHandlerContext ctx)
Calls
ChannelHandlerContext.fireChannelReadComplete() to forward
to the next ChannelInboundHandler in the ChannelPipeline . |
protected void |
decode(ChannelHandlerContext ctx,
HttpObject msg,
java.util.List<java.lang.Object> out)
Decode from one message to an other.
|
protected java.lang.String |
getTargetContentEncoding(java.lang.String contentEncoding)
Returns the expected content encoding of the decoded content.
|
void |
handlerAdded(ChannelHandlerContext ctx)
Do nothing by default, sub-classes may override this method.
|
void |
handlerRemoved(ChannelHandlerContext ctx)
Do nothing by default, sub-classes may override this method.
|
protected abstract EmbeddedChannel |
newContentDecoder(java.lang.String contentEncoding)
Returns a new
EmbeddedChannel that decodes the HTTP message
content encoded in the specified contentEncoding. |
acceptInboundMessage, channelRead
channelActive, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered
ensureNotSharable, isSharable
protected ChannelHandlerContext ctx
protected void decode(ChannelHandlerContext ctx, HttpObject msg, java.util.List<java.lang.Object> out) throws java.lang.Exception
MessageToMessageDecoder
decode
在类中 MessageToMessageDecoder<HttpObject>
ctx
- the ChannelHandlerContext
which this MessageToMessageDecoder
belongs tomsg
- the message to decode to an other oneout
- the List
to which decoded messages should be addedjava.lang.Exception
- is thrown if an error occurspublic void channelReadComplete(ChannelHandlerContext ctx) throws java.lang.Exception
ChannelInboundHandlerAdapter
ChannelHandlerContext.fireChannelReadComplete()
to forward
to the next ChannelInboundHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.channelReadComplete
在接口中 ChannelInboundHandler
channelReadComplete
在类中 ChannelInboundHandlerAdapter
java.lang.Exception
protected abstract EmbeddedChannel newContentDecoder(java.lang.String contentEncoding) throws java.lang.Exception
EmbeddedChannel
that decodes the HTTP message
content encoded in the specified contentEncoding.contentEncoding
- the value of the "Content-Encoding"
headerEmbeddedChannel
if the specified encoding is supported.
null
otherwise (alternatively, you can throw an exception
to block unknown encoding).java.lang.Exception
protected java.lang.String getTargetContentEncoding(java.lang.String contentEncoding) throws java.lang.Exception
"identity"
by default, which is the case for
most decoders.contentEncoding
- the value of the "Content-Encoding"
headerjava.lang.Exception
public void handlerRemoved(ChannelHandlerContext ctx) throws java.lang.Exception
ChannelHandlerAdapter
handlerRemoved
在接口中 ChannelHandler
handlerRemoved
在类中 ChannelHandlerAdapter
java.lang.Exception
public void channelInactive(ChannelHandlerContext ctx) throws java.lang.Exception
ChannelInboundHandlerAdapter
ChannelHandlerContext.fireChannelInactive()
to forward
to the next ChannelInboundHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.channelInactive
在接口中 ChannelInboundHandler
channelInactive
在类中 ChannelInboundHandlerAdapter
java.lang.Exception
public void handlerAdded(ChannelHandlerContext ctx) throws java.lang.Exception
ChannelHandlerAdapter
handlerAdded
在接口中 ChannelHandler
handlerAdded
在类中 ChannelHandlerAdapter
java.lang.Exception