public abstract class HttpContentEncoder extends io.netty.handler.codec.MessageToMessageCodec<HttpMessage,HttpMessage,Object,Object>
HttpResponse
and HttpChunk
.
The original content is replaced with the new content encoded by the
EncoderEmbedder
, which is created by beginEncode(HttpMessage, String)
.
Once encoding is finished, the value of the 'Content-Encoding' header
is set to the target content encoding, as returned by
beginEncode(HttpMessage, 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, 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, String)
properly to make
this class functional. For example, refer to the source code of
HttpContentCompressor
.
This handler must be placed after HttpMessageEncoder
in the pipeline
so that this handler can intercept HTTP responses before HttpMessageEncoder
converts them into ByteBuf
s.
Modifier and Type | Class and Description |
---|---|
static class |
HttpContentEncoder.Result |
Modifier | Constructor and Description |
---|---|
protected |
HttpContentEncoder()
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
void |
afterRemove(io.netty.channel.ChannelHandlerContext ctx) |
protected abstract HttpContentEncoder.Result |
beginEncode(HttpMessage msg,
String acceptEncoding)
Prepare to encode the HTTP message content.
|
void |
channelInactive(io.netty.channel.ChannelHandlerContext ctx) |
HttpMessage |
decode(io.netty.channel.ChannelHandlerContext ctx,
HttpMessage msg) |
Object |
encode(io.netty.channel.ChannelHandlerContext ctx,
Object msg) |
boolean |
isDecodable(Object msg) |
boolean |
isEncodable(Object msg) |
flush, inboundBufferUpdated, newInboundBuffer, newOutboundBuffer
bind, close, connect, deregister, disconnect
afterAdd, beforeAdd, beforeRemove, channelActive, channelRegistered, channelUnregistered, exceptionCaught, userEventTriggered
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
channelActive, channelRegistered, channelUnregistered
public boolean isDecodable(Object msg) throws Exception
isDecodable
in class io.netty.handler.codec.MessageToMessageCodec<HttpMessage,HttpMessage,Object,Object>
Exception
public HttpMessage decode(io.netty.channel.ChannelHandlerContext ctx, HttpMessage msg) throws Exception
decode
in class io.netty.handler.codec.MessageToMessageCodec<HttpMessage,HttpMessage,Object,Object>
Exception
public boolean isEncodable(Object msg) throws Exception
isEncodable
in class io.netty.handler.codec.MessageToMessageCodec<HttpMessage,HttpMessage,Object,Object>
Exception
public Object encode(io.netty.channel.ChannelHandlerContext ctx, Object msg) throws Exception
encode
in class io.netty.handler.codec.MessageToMessageCodec<HttpMessage,HttpMessage,Object,Object>
Exception
protected abstract HttpContentEncoder.Result beginEncode(HttpMessage msg, String acceptEncoding) throws Exception
msg
- the HTTP message whose content should be encodedacceptEncoding
- the value of the "Accept-Encoding"
headerEncoderEmbedder
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).Exception
public void afterRemove(io.netty.channel.ChannelHandlerContext ctx) throws Exception
afterRemove
in interface io.netty.channel.ChannelHandler
afterRemove
in class io.netty.channel.ChannelStateHandlerAdapter
Exception
Copyright © 2008-2012 The Netty Project. All Rights Reserved.