Top Description Fields Constructors Methods
org.apache.coyote.http11.filters

public Class ChunkedInputFilter

extends Object
implements InputFilter, ApplicationBufferHandler
Class Inheritance
All Implemented Interfaces
org.apache.tomcat.util.net.ApplicationBufferHandler, org.apache.coyote.http11.InputFilter, org.apache.coyote.InputBuffer
Imports
java.io.EOFException, .IOException, java.nio.ByteBuffer, java.nio.charset.StandardCharsets, java.util.Locale, .Map, .Set, org.apache.coyote.BadRequestException, .InputBuffer, .Request, org.apache.coyote.http11.Constants, .InputFilter, org.apache.tomcat.util.buf.ByteChunk, .HexUtils, org.apache.tomcat.util.http.parser.HttpParser, org.apache.tomcat.util.net.ApplicationBufferHandler, org.apache.tomcat.util.res.StringManager

Chunked input filter. Parses chunked data according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.6.1
Author
Remy Maucherat

Field Summary

Modifier and TypeField and Description
private final Set<String>
protected InputBuffer
buffer

Next buffer in the pipeline.

protected static final ByteChunk
protected static final String
protected boolean
endChunk

Flag set to true when the end chunk has been read.

private boolean
error

Flag that indicates if an error has occurred.

private long
extensionSize

Size of extensions processed for this request.

private final long
maxExtensionSize

Limit for extension size.

private final int
private final int
maxTrailerSize

Limit for trailer size.

protected boolean
needCRLFParse

Flag set to true if the next call to doRead() must parse a CRLF pair before doing anything else.

protected ByteBuffer
readChunk

Byte chunk used to read bytes.

protected int
remaining

Number of bytes remaining in the current chunk.

private Request
request

Request being parsed.

private static final StringManager
protected final ByteChunk
trailingHeaders

Byte chunk used to store trailing headers.

Constructor Summary

AccessConstructor and Description
public
ChunkedInputFilter(int maxTrailerSize, Set<String> allowedTrailerHeaders, int maxExtensionSize, int maxSwallowSize)

Method Summary

Modifier and TypeMethod and Description
public int
available()

Implements org.apache.coyote.InputBuffer.available.

Amount of bytes still available in a buffer.

private void
public int
doRead(ApplicationBufferHandler
ApplicationBufferHandler that provides the buffer to read data into.
handler
)

Implements org.apache.coyote.InputBuffer.doRead.

Read from the input stream into the ByteBuffer provided by the ApplicationBufferHandler.

public long
end()

Implements org.apache.coyote.http11.InputFilter.end.

End the current request.

public void
public ByteBuffer
public ByteChunk
getEncodingName()

Implements org.apache.coyote.http11.InputFilter.getEncodingName.

Return the name of the associated encoding; Here, the value is "identity".

public boolean
isFinished()

Implements org.apache.coyote.http11.InputFilter.isFinished.

Has the request body been read fully?

protected boolean

Returns:

true if the chunk header has been successfully parsed
parseChunkHeader
()

Parse the header of a chunk.

protected void
parseCRLF(boolean
Should tolerant parsing (LF and CRLF) be used? This is recommended (RFC2616, section 19.3) for message headers.
tolerant
)

Parse CRLF at end of chunk.

protected void
parseEndChunk()

Parse end chunk data.

private boolean
protected int

Returns:

The byte count which has been read
readBytes
()

Read bytes from the previous buffer.

public void
recycle()

Implements org.apache.coyote.http11.InputFilter.recycle.

Make the filter ready to process the next request.

public void
setBuffer(InputBuffer
The next buffer
buffer
)

Implements org.apache.coyote.http11.InputFilter.setBuffer.

Set the next buffer in the filter pipeline.

public void
public void
setRequest(Request
The request to be associated with this filter
request
)

Implements org.apache.coyote.http11.InputFilter.setRequest.

Read the content length from the request.

private void
private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

allowedTrailerHeadersback to summary
private final Set<String> allowedTrailerHeaders
bufferback to summary
protected InputBuffer buffer

Next buffer in the pipeline.

ENCODINGback to summary
protected static final ByteChunk ENCODING
ENCODING_NAMEback to summary
protected static final String ENCODING_NAME
endChunkback to summary
protected boolean endChunk

Flag set to true when the end chunk has been read.

errorback to summary
private boolean error

Flag that indicates if an error has occurred.

extensionSizeback to summary
private long extensionSize

Size of extensions processed for this request.

maxExtensionSizeback to summary
private final long maxExtensionSize

Limit for extension size.

maxSwallowSizeback to summary
private final int maxSwallowSize
maxTrailerSizeback to summary
private final int maxTrailerSize

Limit for trailer size.

needCRLFParseback to summary
protected boolean needCRLFParse

Flag set to true if the next call to doRead() must parse a CRLF pair before doing anything else.

readChunkback to summary
protected ByteBuffer readChunk

Byte chunk used to read bytes.

remainingback to summary
protected int remaining

Number of bytes remaining in the current chunk.

requestback to summary
private Request request

Request being parsed.

smback to summary
private static final StringManager sm
trailingHeadersback to summary
protected final ByteChunk trailingHeaders

Byte chunk used to store trailing headers.

Constructor Detail

ChunkedInputFilterback to summary
public ChunkedInputFilter(int maxTrailerSize, Set<String> allowedTrailerHeaders, int maxExtensionSize, int maxSwallowSize)

Method Detail

availableback to summary
public int available()

Implements org.apache.coyote.InputBuffer.available.

Amount of bytes still available in a buffer.

Returns:int

Doc from org.apache.coyote.InputBuffer.available.

The number of bytes that can be read without blocking

Annotations
@Override
checkErrorback to summary
private void checkError() throws IOException
doReadback to summary
public int doRead(ApplicationBufferHandler handler) throws IOException

Implements org.apache.coyote.InputBuffer.doRead.

Doc from org.apache.coyote.InputBuffer.doRead.

Read from the input stream into the ByteBuffer provided by the ApplicationBufferHandler.

Important Note

the current model assumes that the protocol will 'own' the ByteBuffer and return a pointer to it.

Parameters
handler:ApplicationBufferHandler

ApplicationBufferHandler that provides the buffer to read data into.

Returns:int

The number of bytes that have been added to the buffer or -1 for end of stream

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs reading from the input stream
endback to summary
public long end() throws IOException

Implements org.apache.coyote.http11.InputFilter.end.

End the current request.

Returns:long

Doc from org.apache.coyote.http11.InputFilter.end.

0 is the expected return value. A positive value indicates that too many bytes were read. This method is allowed to use buffer.doRead to consume extra bytes. The result of this method can't be negative (if an error happens, an IOException should be thrown instead).

Annotations
@Override
Exceptions
IOException:

Doc from org.apache.coyote.http11.InputFilter.end.

If an error happens

expandback to summary
public void expand(int size)

Implements org.apache.tomcat.util.net.ApplicationBufferHandler.expand.

Annotations
@Override
getByteBufferback to summary
public ByteBuffer getByteBuffer()

Implements org.apache.tomcat.util.net.ApplicationBufferHandler.getByteBuffer.

Annotations
@Override
getEncodingNameback to summary
public ByteChunk getEncodingName()

Implements org.apache.coyote.http11.InputFilter.getEncodingName.

Return the name of the associated encoding; Here, the value is "identity".

Returns:ByteChunk

Doc from org.apache.coyote.http11.InputFilter.getEncodingName.

The encoding name as a byte chunk to facilitate comparison with the value read from the HTTP headers which will also be a ByteChunk

Annotations
@Override
isFinishedback to summary
public boolean isFinished()

Implements org.apache.coyote.http11.InputFilter.isFinished.

Doc from org.apache.coyote.http11.InputFilter.isFinished.

Has the request body been read fully?

Returns:boolean

true if the request body has been fully read, otherwise false

Annotations
@Override
parseChunkHeaderback to summary
protected boolean parseChunkHeader() throws IOException

Parse the header of a chunk. A chunk header can look like one of the following:
A10CRLF
F23;chunk-extension to be ignoredCRLF

The letters before CRLF or ';' (whatever comes first) must be valid hex digits. We should not parse F23IAMGONNAMESSTHISUP34CRLF as a valid header according to the spec.

Returns:boolean

true if the chunk header has been successfully parsed

Exceptions
IOException:
Read error
parseCRLFback to summary
protected void parseCRLF(boolean tolerant) throws IOException

Parse CRLF at end of chunk.

Parameters
tolerant:boolean

Should tolerant parsing (LF and CRLF) be used? This is recommended (RFC2616, section 19.3) for message headers.

Exceptions
IOException:
An error occurred parsing CRLF
parseEndChunkback to summary
protected void parseEndChunk() throws IOException

Parse end chunk data.

Exceptions
IOException:
Error propagation
parseHeaderback to summary
private boolean parseHeader() throws IOException
readBytesback to summary
protected int readBytes() throws IOException

Read bytes from the previous buffer.

Returns:int

The byte count which has been read

Exceptions
IOException:
Read error
recycleback to summary
public void recycle()

Implements org.apache.coyote.http11.InputFilter.recycle.

Make the filter ready to process the next request.

Annotations
@Override
setBufferback to summary
public void setBuffer(InputBuffer buffer)

Implements org.apache.coyote.http11.InputFilter.setBuffer.

Set the next buffer in the filter pipeline.

Parameters
buffer:InputBuffer

Doc from org.apache.coyote.http11.InputFilter.setBuffer.

The next buffer

Annotations
@Override
setByteBufferback to summary
public void setByteBuffer(ByteBuffer buffer)

Implements org.apache.tomcat.util.net.ApplicationBufferHandler.setByteBuffer.

Annotations
@Override
setRequestback to summary
public void setRequest(Request request)

Implements org.apache.coyote.http11.InputFilter.setRequest.

Read the content length from the request.

Parameters
request:Request

Doc from org.apache.coyote.http11.InputFilter.setRequest.

The request to be associated with this filter

Annotations
@Override
throwBadRequestExceptionback to summary
private void throwBadRequestException(String msg) throws IOException
throwEOFExceptionback to summary
private void throwEOFException(String msg) throws IOException