public abstract class HttpObjectDecoder extends ByteToMessageDecoder
ByteBuf
s解码为HttpMessage
s和HttpContent
s。
maxInitialLineLength
The maximum length of the initial line (e.g. "GET / HTTP/1.0"
or "HTTP/1.0 200 OK"
) If the length of the initial line exceeds this value, a TooLongFrameException
will be raised. maxHeaderSize
The maximum length of all headers. If the sum of the length of each header exceeds this value, a TooLongFrameException
will be raised. maxChunkSize
The maximum length of the content or each chunk. If the content length (or the length of each chunk) exceeds this value, the content or chunk will be split into multiple HttpContent
s whose length is maxChunkSize
at maximum.
maxChunkSize
或者HTTP消息的传输编码是“分块”,则该解码器将为每个HTTP消息生成一个HttpMessage
实例及其后续HttpContent
个实例,以避免过多的内存消耗。
例如,下面的HTTP消息:
GET / HTTP/1.1
Transfer-Encoding: chunked
1a
abcdefghijklmnopqrstuvwxyz
10
1234567890abcdef
0
Content-MD5: ...
[blank line]
触发HttpRequestDecoder
以生成3个对象:
HttpRequest
, HttpContent
,其内容是'abcdefghijklmnopqrstuvwxyz'
, LastHttpContent
,其内容是'1234567890abcdef'
,标志着内容的结束。 HttpContent
,请在ChannelPipeline
的此解码器后插入HttpObjectAggregator
。
但是,请注意,您的服务器可能没有聚合器的内存效率。
ByteToMessageDecoder.Cumulator
ChannelHandler.Sharable
Modifier and Type | Field and Description |
---|---|
protected boolean |
validateHeaders |
COMPOSITE_CUMULATOR, MERGE_CUMULATOR
Modifier | Constructor and Description |
---|---|
protected |
HttpObjectDecoder()
使用默认值
maxInitialLineLength (4096 },
maxHeaderSize (8192) 和
maxChunkSize (8192) 创建一个新实例。
|
protected |
HttpObjectDecoder(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean chunkedSupported)
用指定的参数创建一个新的实例。
|
protected |
HttpObjectDecoder(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean chunkedSupported, boolean validateHeaders)
用指定的参数创建一个新的实例。
|
protected |
HttpObjectDecoder(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean chunkedSupported, boolean validateHeaders, int initialBufferSize) |
Modifier and Type | Method and Description |
---|---|
protected abstract HttpMessage |
createInvalidMessage() |
protected abstract HttpMessage |
createMessage(java.lang.String[] initialLine) |
protected void |
decode(ChannelHandlerContext ctx, ByteBuf buffer, java.util.List<java.lang.Object> out)
解码从一个 ByteBuf 到另一个。
|
protected void |
decodeLast(ChannelHandlerContext ctx, ByteBuf in, java.util.List<java.lang.Object> out)
最后一次被称为 ChannelHandlerContext 无效时。
|
protected boolean |
isContentAlwaysEmpty(HttpMessage msg) |
protected abstract boolean |
isDecodingRequest() |
protected boolean |
isSwitchingToNonHttp1Protocol(HttpResponse msg)
如果服务器切换到不同于HTTP / 1.0或HTTP / 1.1的协议,则返回true,例如
|
void |
reset()
重置解码器的状态,以便它可以解码新消息。
|
void |
userEventTriggered(ChannelHandlerContext ctx, java.lang.Object evt)
|
actualReadableBytes, callDecode, channelInactive, channelRead, channelReadComplete, discardSomeReadBytes, handlerRemoved, handlerRemoved0, internalBuffer, isSingleDecode, setCumulator, setDiscardAfterReads, setSingleDecode
channelActive, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught
ensureNotSharable, handlerAdded, isSharable
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
handlerAdded
protected HttpObjectDecoder()
maxInitialLineLength (4096
},
maxHeaderSize (8192)
和
maxChunkSize (8192)
创建一个新实例。
protected HttpObjectDecoder(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean chunkedSupported)
protected HttpObjectDecoder(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean chunkedSupported, boolean validateHeaders)
protected HttpObjectDecoder(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean chunkedSupported, boolean validateHeaders, int initialBufferSize)
protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, java.util.List<java.lang.Object> out) throws java.lang.Exception
ByteToMessageDecoder
decode
在课程
ByteToMessageDecoder
ctx
- 这ByteToMessageDecoder
所属的ChannelHandlerContext
buffer
- 从中读取数据的ByteBuf
out
- 应该添加解码消息的
List
java.lang.Exception
- 发生错误时抛出
protected void decodeLast(ChannelHandlerContext ctx, ByteBuf in, java.util.List<java.lang.Object> out) throws java.lang.Exception
ByteToMessageDecoder
ChannelHandlerContext
处于非活动状态时称为最后一次。
这意味着ByteToMessageDecoder.channelInactive(ChannelHandlerContext)
被触发。
默认情况下,这只会调用ByteToMessageDecoder.decode(ChannelHandlerContext, ByteBuf, List)
,但子类可能会覆盖这个对于一些特殊的清理操作。
decodeLast
在课堂上
ByteToMessageDecoder
java.lang.Exception
public void userEventTriggered(ChannelHandlerContext ctx, java.lang.Object evt) throws java.lang.Exception
ChannelInboundHandlerAdapter
ChannelHandlerContext.fireUserEventTriggered(Object)
转发到ChannelPipeline
中的下一个ChannelInboundHandler
。
子类可以重写此方法来更改行为。
userEventTriggered
接口
ChannelInboundHandler
userEventTriggered
在课堂上
ByteToMessageDecoder
java.lang.Exception
protected boolean isContentAlwaysEmpty(HttpMessage msg)
protected boolean isSwitchingToNonHttp1Protocol(HttpResponse msg)
public void reset()
Expect: 100-continue
标头处理拒绝的请求很有用。
protected abstract boolean isDecodingRequest()
protected abstract HttpMessage createMessage(java.lang.String[] initialLine) throws java.lang.Exception
java.lang.Exception
protected abstract HttpMessage createInvalidMessage()
Copyright © 2008–2018 The Netty Project. All rights reserved.