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
-
Nested Class Summary
Nested classes/interfaces inherited from class io.netty.handler.codec.ByteToMessageDecoder
ByteToMessageDecoder.CumulatorNested 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, validateHeadersFields inherited from class io.netty.handler.codec.ByteToMessageDecoder
COMPOSITE_CUMULATOR, MERGE_CUMULATOR -
Constructor Summary
Constructors -
Method Summary
Methods inherited from class io.netty.handler.codec.http.HttpRequestDecoder
createInvalidMessage, createMessage, isContentAlwaysEmpty, isDecodingRequest, splitFirstWordInitialLine, splitHeaderName, splitThirdWordInitialLineMethods inherited from class io.netty.handler.codec.http.HttpObjectDecoder
clearContentLength, decodeLast, handlerRemoved0, isSwitchingToNonHttp1Protocol, isValidating, reset, splitSecondWordInitialLine, userEventTriggeredMethods inherited from class io.netty.handler.codec.ByteToMessageDecoder
actualReadableBytes, callDecode, channelInactive, channelRead, channelReadComplete, discardSomeReadBytes, handlerRemoved, internalBuffer, isSingleDecode, setCumulator, setDiscardAfterReads, setSingleDecodeMethods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaughtMethods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerAdded, isSharableMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.netty.channel.ChannelHandler
handlerAdded
-
Constructor Details
-
HttpServerRequestDecoder
HttpServerRequestDecoder(HttpDecoderConfig config)
-
-
Method Details
-
decode
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:
Exception- is thrown if an error occurs
-
handleTransferEncodingChunkedWithContentLength
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:
@Override protected void handleTransferEncodingChunkedWithContentLength(HttpMessage message) { clearContentLength(); message.headers().remove(HttpHeaderNames.CONTENT_LENGTH); }
Note: This method is only called for
HTTP/1.1requests. Earlier HTTP protocol versions do not support theTransfer-Encodingheader, and will reject requests that include it.- Overrides:
handleTransferEncodingChunkedWithContentLengthin classHttpObjectDecoder
-
Process-wide, by setting the "io.netty.handler.codec.http.rfc9112TransferEncoding" system property to
-