Package io.netty.handler.codec.http
Class HttpServerCodec.HttpServerRequestDecoder
- java.lang.Object
-
- io.netty.channel.ChannelHandlerAdapter
-
- io.netty.channel.ChannelInboundHandlerAdapter
-
- io.netty.handler.codec.ByteToMessageDecoder
-
- io.netty.handler.codec.http.HttpObjectDecoder
-
- io.netty.handler.codec.http.HttpRequestDecoder
-
- io.netty.handler.codec.http.HttpServerCodec.HttpServerRequestDecoder
-
- All Implemented Interfaces:
ChannelHandler,ChannelInboundHandler
- Enclosing class:
- HttpServerCodec
private final class HttpServerCodec.HttpServerRequestDecoder extends HttpRequestDecoder
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class io.netty.handler.codec.ByteToMessageDecoder
ByteToMessageDecoder.Cumulator
-
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
-
Field Summary
-
Fields inherited from class io.netty.handler.codec.http.HttpObjectDecoder
DEFAULT_ALLOW_DUPLICATE_CONTENT_LENGTHS, DEFAULT_ALLOW_PARTIAL_CHUNKS, DEFAULT_CHUNKED_SUPPORTED, DEFAULT_INITIAL_BUFFER_SIZE, DEFAULT_MAX_CHUNK_SIZE, DEFAULT_MAX_HEADER_SIZE, DEFAULT_MAX_INITIAL_LINE_LENGTH, DEFAULT_STRICT_LINE_PARSING, DEFAULT_VALIDATE_HEADERS, headersFactory, PROP_RFC9112_TRANSFER_ENCODING, RFC9112_TRANSFER_ENCODING, trailersFactory, validateHeaders
-
Fields inherited from class io.netty.handler.codec.ByteToMessageDecoder
COMPOSITE_CUMULATOR, MERGE_CUMULATOR
-
-
Constructor Summary
Constructors Constructor Description HttpServerRequestDecoder(HttpDecoderConfig config)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voiddecode(ChannelHandlerContext ctx, ByteBuf buffer, java.util.List<java.lang.Object> out)Decode the from oneByteBufto an other.protected voidhandleTransferEncodingChunkedWithContentLength(HttpMessage message)Invoked when a message with both a "Transfer-Encoding: chunked" and a "Content-Length" header field is detected.-
Methods inherited from class io.netty.handler.codec.http.HttpRequestDecoder
createInvalidMessage, createMessage, isContentAlwaysEmpty, isDecodingRequest, splitFirstWordInitialLine, splitHeaderName, splitThirdWordInitialLine
-
Methods inherited from class io.netty.handler.codec.http.HttpObjectDecoder
clearContentLength, decodeLast, handlerRemoved0, isSwitchingToNonHttp1Protocol, isValidating, reset, splitSecondWordInitialLine, userEventTriggered
-
Methods inherited from class io.netty.handler.codec.ByteToMessageDecoder
actualReadableBytes, callDecode, channelInactive, channelRead, channelReadComplete, discardSomeReadBytes, handlerRemoved, internalBuffer, isSingleDecode, setCumulator, setDiscardAfterReads, setSingleDecode
-
Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught
-
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerAdded, isSharable
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.netty.channel.ChannelHandler
handlerAdded
-
-
-
-
Constructor Detail
-
HttpServerRequestDecoder
HttpServerRequestDecoder(HttpDecoderConfig config)
-
-
Method Detail
-
decode
protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, java.util.List<java.lang.Object> out) throws java.lang.Exception
Description copied from class:ByteToMessageDecoderDecode the from oneByteBufto an other. This method will be called till either the inputByteBufhas nothing to read when return from this method or till nothing was read from the inputByteBuf.- Overrides:
decodein classHttpObjectDecoder- Parameters:
ctx- theChannelHandlerContextwhich thisByteToMessageDecoderbelongs tobuffer- theByteBuffrom which to read dataout- theListto which decoded messages should be added- Throws:
java.lang.Exception- is thrown if an error occurs
-
handleTransferEncodingChunkedWithContentLength
protected void handleTransferEncodingChunkedWithContentLength(HttpMessage message)
Description copied from class:HttpObjectDecoderInvoked when a message with both a "Transfer-Encoding: chunked" and a "Content-Length" header field is detected. The default behavior is to throw aContentLengthNotAllowedExceptionexception, but this method could be overridden to change the behavior (to, e.g., remove theContent-Lengthheader value.See: RFC 9112, Section 6.1-15.
A server MAY reject a request that contains both Content-Length and Transfer-Encoding or process such a request in accordance with the Transfer-Encoding alone. Regardless, the server MUST close the connection after responding to such a request to avoid the potential attacks.Since Netty itself cannot track the request/response pairing, it cannot guarantee that the connection is closed immediately after the response is sent. As such, it is safer to immediately reject the request.Note: RFC 7230 (the previous HTTP/1.1 RFC) allowed the
Content-Lengthheader to simply be ignored, in the presence of aTransfer-Encodingheader, but this practice is now obsolete and considered unsafe. The RFC 7230 behavior can be restored in the following ways:-
Process-wide, by setting the "io.netty.handler.codec.http.rfc9112TransferEncoding" system property to
false. -
Configured for a specific decoder, by setting
HttpDecoderConfig.setUseRfc9112TransferEncoding(boolean)tofalse. -
Hard-coded for a specific decoder, by overriding this method with an implementation like the following:
{@code
- Overrides:
handleTransferEncodingChunkedWithContentLengthin classHttpObjectDecoder
-
Process-wide, by setting the "io.netty.handler.codec.http.rfc9112TransferEncoding" system property to
-
-