public abstract class HttpContentEncoder extends SimpleChannelHandler implements LifeCycleAwareChannelHandler
HttpResponse and HttpChunk.
The original content is replaced with the new content encoded by the
EncoderEmbedder, which is created by newContentEncoder(HttpMessage, String).
Once encoding 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
encoded content. If there is no supported encoding in the
corresponding HttpRequest's "Accept-Encoding" header,
newContentEncoder(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 newContentEncoder(HttpMessage, String) and getTargetContentEncoding(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 ChannelBuffers.
ChannelHandler.Sharable| 限定符 | 构造器和说明 |
|---|---|
protected |
HttpContentEncoder()
Creates a new instance.
|
| 限定符和类型 | 方法和说明 |
|---|---|
void |
afterAdd(ChannelHandlerContext ctx) |
void |
afterRemove(ChannelHandlerContext ctx) |
void |
beforeAdd(ChannelHandlerContext ctx) |
void |
beforeRemove(ChannelHandlerContext ctx) |
void |
channelClosed(ChannelHandlerContext ctx,
ChannelStateEvent e)
Invoked when a
Channel was closed and all its related resources
were released. |
protected abstract java.lang.String |
getTargetContentEncoding(java.lang.String acceptEncoding)
Returns the expected content encoding of the encoded content.
|
void |
messageReceived(ChannelHandlerContext ctx,
MessageEvent e)
Invoked when a message object (e.g:
ChannelBuffer) was received
from a remote peer. |
protected abstract EncoderEmbedder<ChannelBuffer> |
newContentEncoder(HttpMessage msg,
java.lang.String acceptEncoding)
Returns a new
EncoderEmbedder that encodes the HTTP message
content. |
void |
writeRequested(ChannelHandlerContext ctx,
MessageEvent e)
Invoked when
Channel.write(Object) is called. |
bindRequested, channelBound, channelConnected, channelDisconnected, channelInterestChanged, channelOpen, channelUnbound, childChannelClosed, childChannelOpen, closeRequested, connectRequested, disconnectRequested, exceptionCaught, handleDownstream, handleUpstream, setInterestOpsRequested, unbindRequested, writeCompletepublic void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws java.lang.Exception
SimpleChannelHandlerChannelBuffer) was received
from a remote peer.messageReceived 在类中 SimpleChannelHandlerjava.lang.Exceptionpublic void writeRequested(ChannelHandlerContext ctx, MessageEvent e) throws java.lang.Exception
SimpleChannelHandlerChannel.write(Object) is called.writeRequested 在类中 SimpleChannelHandlerjava.lang.Exceptionpublic void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws java.lang.Exception
SimpleChannelHandlerChannel was closed and all its related resources
were released.channelClosed 在类中 SimpleChannelHandlerjava.lang.Exceptionprotected abstract EncoderEmbedder<ChannelBuffer> newContentEncoder(HttpMessage msg, java.lang.String acceptEncoding) throws java.lang.Exception
EncoderEmbedder that encodes the HTTP message
content.acceptEncoding - the value of the "Accept-Encoding" headerEncoderEmbedder if there is a supported encoding
in acceptEncoding. null otherwise.java.lang.Exceptionprotected abstract java.lang.String getTargetContentEncoding(java.lang.String acceptEncoding)
throws java.lang.Exception
acceptEncoding - the value of the "Accept-Encoding" headerjava.lang.Exceptionpublic void beforeAdd(ChannelHandlerContext ctx) throws java.lang.Exception
beforeAdd 在接口中 LifeCycleAwareChannelHandlerjava.lang.Exceptionpublic void afterAdd(ChannelHandlerContext ctx) throws java.lang.Exception
afterAdd 在接口中 LifeCycleAwareChannelHandlerjava.lang.Exceptionpublic void beforeRemove(ChannelHandlerContext ctx) throws java.lang.Exception
beforeRemove 在接口中 LifeCycleAwareChannelHandlerjava.lang.Exceptionpublic void afterRemove(ChannelHandlerContext ctx) throws java.lang.Exception
afterRemove 在接口中 LifeCycleAwareChannelHandlerjava.lang.Exception