public abstract class HttpContentEncoder extends io.netty.handler.codec.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.
| Modifier and Type | Class and Description |
|---|---|
static class |
HttpContentEncoder.Result |
| Constructor and Description |
|---|
HttpContentEncoder() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
acceptOutboundMessage(Object msg) |
protected abstract HttpContentEncoder.Result |
beginEncode(HttpResponse headers,
String acceptEncoding)
Prepare to encode the HTTP message content.
|
void |
channelInactive(io.netty.channel.ChannelHandlerContext ctx) |
protected void |
decode(io.netty.channel.ChannelHandlerContext ctx,
HttpRequest msg,
List<Object> out) |
protected void |
encode(io.netty.channel.ChannelHandlerContext ctx,
HttpObject msg,
List<Object> out) |
void |
handlerRemoved(io.netty.channel.ChannelHandlerContext ctx) |
acceptInboundMessage, channelRead, writebind, close, connect, deregister, disconnect, flush, readchannelActive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggeredpublic boolean acceptOutboundMessage(Object msg) throws Exception
acceptOutboundMessage in class io.netty.handler.codec.MessageToMessageCodec<HttpRequest,HttpObject>Exceptionprotected void decode(io.netty.channel.ChannelHandlerContext ctx,
HttpRequest msg,
List<Object> out)
throws Exception
decode in class io.netty.handler.codec.MessageToMessageCodec<HttpRequest,HttpObject>Exceptionprotected void encode(io.netty.channel.ChannelHandlerContext ctx,
HttpObject msg,
List<Object> out)
throws Exception
encode in class io.netty.handler.codec.MessageToMessageCodec<HttpRequest,HttpObject>Exceptionprotected abstract HttpContentEncoder.Result beginEncode(HttpResponse headers, String acceptEncoding) throws Exception
headers - the headersacceptEncoding - 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).Exceptionpublic void handlerRemoved(io.netty.channel.ChannelHandlerContext ctx)
throws Exception
handlerRemoved in interface io.netty.channel.ChannelHandlerhandlerRemoved in class io.netty.channel.ChannelHandlerAdapterExceptionCopyright © 2008–2017 The Netty Project. All rights reserved.