public abstract class HttpContentEncoder extends MessageToMessageCodec<HttpRequest,HttpObject>
HttpResponse and HttpContent.
The original content is replaced with the new content encoded by the
EmbeddedChannel, which is created by beginEncode(HttpResponse, String).
Once encoding is finished, the value of the 'Content-Encoding' header
is set to the target content encoding, as returned by
beginEncode(HttpResponse, String).
Also, the 'Content-Length' header is updated to the length of the
encoded content. If there is no supported or allowed encoding in the
corresponding HttpRequest's "Accept-Encoding" header,
beginEncode(HttpResponse, String) should return null so that
no encoding occurs (i.e. pass-through).
Please note that this is an abstract class. You have to extend this class
and implement beginEncode(HttpResponse, String) properly to make
this class functional. For example, refer to the source code of
HttpContentCompressor.
This handler must be placed after HttpObjectEncoder in the pipeline
so that this handler can intercept HTTP responses before HttpObjectEncoder
converts them into ByteBufs.
| 限定符和类型 | 类和说明 |
|---|---|
static class |
HttpContentEncoder.Result |
ChannelHandler.Sharable| 构造器和说明 |
|---|
HttpContentEncoder() |
| 限定符和类型 | 方法和说明 |
|---|---|
boolean |
acceptOutboundMessage(java.lang.Object msg)
Returns
true if and only if the specified message can be encoded by this codec. |
protected abstract HttpContentEncoder.Result |
beginEncode(HttpResponse httpResponse,
java.lang.String acceptEncoding)
Prepare to encode the HTTP message content.
|
void |
channelInactive(ChannelHandlerContext ctx)
Calls
ChannelHandlerContext.fireChannelInactive() to forward
to the next ChannelInboundHandler in the ChannelPipeline. |
protected void |
decode(ChannelHandlerContext ctx,
HttpRequest msg,
java.util.List<java.lang.Object> out) |
protected void |
encode(ChannelHandlerContext ctx,
HttpObject msg,
java.util.List<java.lang.Object> out) |
void |
handlerRemoved(ChannelHandlerContext ctx)
Do nothing by default, sub-classes may override this method.
|
acceptInboundMessage, channelRead, writebind, close, connect, deregister, disconnect, flush, readchannelActive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggeredensureNotSharable, handlerAdded, isSharableclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitexceptionCaught, handlerAddedpublic boolean acceptOutboundMessage(java.lang.Object msg)
throws java.lang.Exception
MessageToMessageCodectrue if and only if the specified message can be encoded by this codec.acceptOutboundMessage 在类中 MessageToMessageCodec<HttpRequest,HttpObject>msg - the messagejava.lang.Exceptionprotected void decode(ChannelHandlerContext ctx, HttpRequest msg, java.util.List<java.lang.Object> out) throws java.lang.Exception
decode 在类中 MessageToMessageCodec<HttpRequest,HttpObject>java.lang.ExceptionMessageToMessageDecoder.decode(ChannelHandlerContext, Object, List)protected void encode(ChannelHandlerContext ctx, HttpObject msg, java.util.List<java.lang.Object> out) throws java.lang.Exception
encode 在类中 MessageToMessageCodec<HttpRequest,HttpObject>java.lang.ExceptionMessageToMessageEncoder.encode(ChannelHandlerContext, Object, List)protected abstract HttpContentEncoder.Result beginEncode(HttpResponse httpResponse, java.lang.String acceptEncoding) throws java.lang.Exception
httpResponse - the http responseacceptEncoding - the value of the "Accept-Encoding" headerEmbeddedChannel that
encodes the content into the target content encoding.
null if acceptEncoding is unsupported or rejected
and thus the content should be handled as-is (i.e. no encoding).java.lang.Exceptionpublic void handlerRemoved(ChannelHandlerContext ctx) throws java.lang.Exception
ChannelHandlerAdapterhandlerRemoved 在接口中 ChannelHandlerhandlerRemoved 在类中 ChannelHandlerAdapterjava.lang.Exceptionpublic void channelInactive(ChannelHandlerContext ctx) throws java.lang.Exception
ChannelInboundHandlerAdapterChannelHandlerContext.fireChannelInactive() to forward
to the next ChannelInboundHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.channelInactive 在接口中 ChannelInboundHandlerchannelInactive 在类中 ChannelInboundHandlerAdapterjava.lang.Exception