public abstract class HttpContentEncoder extends io.netty.handler.codec.MessageToMessageCodec<HttpMessage,HttpObject>
HttpResponse and HttpContent.
The original content is replaced with the new content encoded by the
EmbeddedByteChannel, which is created by beginEncode(HttpMessage, HttpContent, String).
Once encoding is finished, the value of the 'Content-Encoding' header
is set to the target content encoding, as returned by
beginEncode(HttpMessage, HttpContent, 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(HttpMessage, HttpContent, 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(HttpMessage, HttpContent, 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.
| Modifier and Type | Class and Description |
|---|---|
static class |
HttpContentEncoder.Result |
| Constructor and Description |
|---|
HttpContentEncoder() |
| Modifier and Type | Method and Description |
|---|---|
void |
afterRemove(io.netty.channel.ChannelHandlerContext ctx) |
protected abstract HttpContentEncoder.Result |
beginEncode(HttpMessage header,
HttpContent msg,
String acceptEncoding)
Prepare to encode the HTTP message content.
|
void |
channelInactive(io.netty.channel.ChannelHandlerContext ctx) |
protected Object |
decode(io.netty.channel.ChannelHandlerContext ctx,
HttpMessage msg) |
protected Object |
encode(io.netty.channel.ChannelHandlerContext ctx,
HttpObject msg) |
acceptInboundMessage, acceptOutboundMessage, flush, freeInboundBuffer, freeOutboundBuffer, inboundBufferUpdated, newInboundBuffer, newOutboundBufferbind, close, connect, deregister, disconnect, read, sendFilechannelActive, channelReadSuspended, channelRegistered, channelUnregistered, userEventTriggeredafterAdd, beforeAdd, beforeRemove, exceptionCaughtclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitchannelActive, channelReadSuspended, channelRegistered, channelUnregistered, userEventTriggeredprotected Object decode(io.netty.channel.ChannelHandlerContext ctx, HttpMessage msg) throws Exception
decode in class io.netty.handler.codec.MessageToMessageCodec<HttpMessage,HttpObject>Exceptionprotected Object encode(io.netty.channel.ChannelHandlerContext ctx, HttpObject msg) throws Exception
encode in class io.netty.handler.codec.MessageToMessageCodec<HttpMessage,HttpObject>Exceptionprotected abstract HttpContentEncoder.Result beginEncode(HttpMessage header, HttpContent msg, String acceptEncoding) throws Exception
header - the headermsg - the HTTP message whose content should be encodedacceptEncoding - the value of the "Accept-Encoding" headerEmbeddedByteChannel 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).Exceptionpublic void afterRemove(io.netty.channel.ChannelHandlerContext ctx)
throws Exception
afterRemove in interface io.netty.channel.ChannelHandlerafterRemove in class io.netty.channel.ChannelHandlerAdapterExceptionCopyright © 2008-2013 The Netty Project. All Rights Reserved.