public abstract class HttpContentDecoder extends MessageToMessageDecoder<HttpObject>
HttpRequest和HttpContent的内容 。
原来的内容被替换为解码后的新内容EmbeddedChannel ,这是由创建newContentDecoder(String) 。
解码完成后, 'Content-Encoding'标头的值被设置为目标内容编码,由getTargetContentEncoding(String)返回。
此外, 'Content-Length'标题更新为解码内容的长度。
如果解码器不支持原始内容编码, newContentDecoder(String)应该返回null以便不发生解码(即直通)。
请注意,这是一个抽象类。 您必须扩展此类并正确实施newContentDecoder(String)以使此类功能正常。 例如,请参阅HttpContentDecompressor的源代码。
该处理程序必须放置在管道HttpObjectDecoder之后,以便此处理程序可以在HttpObjectDecoder将ByteBuf转换为HTTP请求之后拦截HTTP请求。
ChannelHandler.Sharable| Modifier and Type | Field and Description |
|---|---|
protected ChannelHandlerContext |
ctx |
| Constructor and Description |
|---|
HttpContentDecoder() |
| Modifier and Type | Method and Description |
|---|---|
void |
channelInactive(ChannelHandlerContext ctx)
|
protected void |
decode(ChannelHandlerContext ctx, HttpObject msg, java.util.List<java.lang.Object> out)
从一条消息解码到另一条消息。
|
protected java.lang.String |
getTargetContentEncoding(java.lang.String contentEncoding)
返回解码内容的预期内容编码。
|
void |
handlerAdded(ChannelHandlerContext ctx)
子类可以忽略这个方法。
|
void |
handlerRemoved(ChannelHandlerContext ctx)
子类可以忽略这个方法。
|
protected abstract EmbeddedChannel |
newContentDecoder(java.lang.String contentEncoding)
返回一个新的 EmbeddedChannel ,它解码在指定的contentEncoding中编码的HTTP消息内容。
|
acceptInboundMessage, channelReadchannelActive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggeredensureNotSharable, isSharableprotected ChannelHandlerContext ctx
protected void decode(ChannelHandlerContext ctx, HttpObject msg, java.util.List<java.lang.Object> out) throws java.lang.Exception
MessageToMessageDecoder
decode在课堂
MessageToMessageDecoder<HttpObject>
ctx - 此MessageToMessageDecoder所属的ChannelHandlerContext
msg - 解码到另一个的消息
out - 应该添加解码消息的
List
java.lang.Exception - 发生错误时抛出
protected abstract EmbeddedChannel newContentDecoder(java.lang.String contentEncoding) throws java.lang.Exception
EmbeddedChannel ,它解码在指定的contentEncoding中编码的HTTP消息内容。
contentEncoding -
"Content-Encoding"标题的值
EmbeddedChannel 。
null否则(或者,您可以抛出异常来阻止未知编码)。
java.lang.Exception
protected java.lang.String getTargetContentEncoding(java.lang.String contentEncoding)
throws java.lang.Exception
"identity" ,大多数解码器都是这种情况。
contentEncoding -
"Content-Encoding"标题的值
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
public void handlerAdded(ChannelHandlerContext ctx) throws java.lang.Exception
ChannelHandlerAdapter
handlerAdded接口
ChannelHandler
handlerAdded在课堂上
ChannelHandlerAdapter
java.lang.Exception
Copyright © 2008–2018 The Netty Project. All rights reserved.