public abstract class HttpContentEncoder extends MessageToMessageCodec<HttpRequest,HttpObject>
HttpResponse和HttpContent的内容 。
原始内容将被由beginEncode(HttpResponse, String)创建的EmbeddedChannel编码的新内容替换。
编码完成后, 'Content-Encoding'标头的值将设置为目标内容编码,由beginEncode(HttpResponse, String)返回。
此外, 'Content-Length'标题更新为编码内容的长度。
如果在相应的无支持或允许编码HttpRequest的"Accept-Encoding"头, beginEncode(HttpResponse, String)应返回null使得没有编码发生(即直通)。
请注意,这是一个抽象类。 您必须扩展此类并正确实施beginEncode(HttpResponse, String)以使此类功能正常。 例如,请参阅源代码HttpContentCompressor 。
该处理程序必须放置在管道中的HttpObjectEncoder之后,以便此处理程序可以在HttpObjectEncoder将它们转换为ByteBuf之前拦截HTTP响应。
| Modifier and Type | Class and Description |
|---|---|
static class |
HttpContentEncoder.Result |
ChannelHandler.Sharable| Constructor and Description |
|---|
HttpContentEncoder() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
acceptOutboundMessage(java.lang.Object msg)
当且仅当指定的消息可以由此编解码器编码时返回
true 。
|
protected abstract HttpContentEncoder.Result |
beginEncode(HttpResponse headers, java.lang.String acceptEncoding)
准备编码HTTP消息内容。
|
void |
channelInactive(ChannelHandlerContext ctx)
|
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)
子类可以忽略这个方法。
|
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
MessageToMessageCodec
true 。
acceptOutboundMessage在课堂上
MessageToMessageCodec<HttpRequest,HttpObject>
msg - 消息
java.lang.Exception
protected void decode(ChannelHandlerContext ctx, HttpRequest msg, java.util.List<java.lang.Object> out) throws java.lang.Exception
decode
MessageToMessageCodec<HttpRequest,HttpObject>
java.lang.Exception
MessageToMessageDecoder.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.Exception
MessageToMessageEncoder.encode(ChannelHandlerContext, Object, List)
protected abstract HttpContentEncoder.Result beginEncode(HttpResponse headers, java.lang.String acceptEncoding) throws java.lang.Exception
headers - 标题
acceptEncoding -
"Accept-Encoding"标题的值
EmbeddedChannel组成。
null如果acceptEncoding不被支持或拒绝,因此内容应按原样处理(即不编码)。
java.lang.Exception
public void handlerRemoved(ChannelHandlerContext ctx) throws java.lang.Exception
ChannelHandlerAdapter
handlerRemoved在界面
ChannelHandler
handlerRemoved
ChannelHandlerAdapter
java.lang.Exception
public void channelInactive(ChannelHandlerContext ctx) throws java.lang.Exception
ChannelInboundHandlerAdapter
ChannelHandlerContext.fireChannelInactive()转发到ChannelPipeline中的下一个ChannelInboundHandler 。
子类可以重写此方法来更改行为。
channelInactive在界面
ChannelInboundHandler
channelInactive在课堂上
ChannelInboundHandlerAdapter
java.lang.Exception
Copyright © 2008–2018 The Netty Project. All rights reserved.