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

public Class Http11InputBuffer

extends Object
implements InputBuffer, ApplicationBufferHandler
Class Inheritance
All Implemented Interfaces
org.apache.tomcat.util.net.ApplicationBufferHandler, org.apache.coyote.InputBuffer
Imports
java.io.EOFException, .IOException, java.nio.ByteBuffer, java.nio.charset.StandardCharsets, java.util.Arrays, org.apache.coyote.CloseNowException, .InputBuffer, .Request, org.apache.juli.logging.Log, .LogFactory, org.apache.tomcat.util.buf.MessageBytes, org.apache.tomcat.util.http.HeaderUtil, .MimeHeaders, org.apache.tomcat.util.http.parser.HttpParser, org.apache.tomcat.util.net.ApplicationBufferHandler, .SocketWrapperBase, org.apache.tomcat.util.res.StringManager

InputBuffer for HTTP that provides request header parsing as well as transfer encoding.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static enum
private static enum
private class
Http11InputBuffer.SocketInputBuffer

This class is an input buffer which will read its data from an input stream.

Field Summary

Modifier and TypeField and Description
private InputFilter[]
activeFilters

Active filters (in order).

private ByteBuffer
byteBuffer

The read buffer.

private byte
private static final byte[]
private int
end

Pos of the end of the header in the buffer, which is also the start of the body.

private InputFilter[]
filterLibrary

Filter library.

private final int
headerBufferSize

Maximum allowed size of the HTTP request line plus headers plus any leading blank lines.

private final Http11InputBuffer.HeaderParseData
private Http11InputBuffer.HeaderParsePosition
private final MimeHeaders
headers

Headers of the associated request.

private final HttpParser
private InputBuffer
inputStreamInputBuffer

Underlying input buffer.

private int
lastActiveFilter

Index of the last active filter.

private static final Log
private volatile boolean
private volatile boolean
private boolean
private int
private int
private int
private byte
prevChr

Parsing state - used for non blocking parsing so that when more data arrives, we can pick up where we left off.

private final boolean
private final Request
request

Associated Coyote request.

private static final StringManager
sm

The string manager for this package.

private int
socketReadBufferSize

Known size of the NioChannel read buffer.

private boolean
swallowInput

Swallow input ?

private SocketWrapperBase<?>
wrapper

Wrapper that provides access to the underlying socket.

Constructor Summary

AccessConstructor and Description
public
Http11InputBuffer(Request request, int headerBufferSize, boolean rejectIllegalHeader, HttpParser httpParser)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
addActiveFilter(InputFilter filter)

Add an input filter to the filter library.

pack-priv void
addFilter(InputFilter filter)

Add an input filter to the filter library.

public int
available()

Implements org.apache.coyote.InputBuffer.available.

Obtain an estimate of the number of bytes that can be read without blocking.

pack-priv int
available(boolean read)

Available bytes in the buffers for the current request.

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.

pack-priv void
endRequest()

End request (consumes leftover bytes).

public void
private boolean

Returns:

true if more data was added to the input buffer otherwise false
fill
(boolean block)

Attempts to read some data into the input buffer.

public ByteBuffer
pack-priv InputFilter[]
getFilters()

Get filters.

pack-priv ByteBuffer
pack-priv int
pack-priv void
init(SocketWrapperBase<?> socketWrapper)

pack-priv boolean
pack-priv boolean
isFinished()

Has all of the request body been read?

pack-priv void
nextRequest()

End processing of current HTTP request.

private Http11InputBuffer.HeaderParseStatus
pack-priv boolean
parseHeaders()

Parse the HTTP headers.

private String
parseInvalid(int startPos, ByteBuffer buffer)

pack-priv boolean

Returns:

true if data is properly fed; false if no data is available immediately and thread should be freed
parseRequestLine
(boolean keptAlive, int connectionTimeout, int keepAliveTimeout)

Read the request line.

pack-priv void
recycle()

Recycle the input buffer.

public void
pack-priv void
setSwallowInput(boolean swallowInput)

Set the swallow input flag.

private Http11InputBuffer.HeaderParseStatus
skipLine(boolean deleteHeader)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

activeFiltersback to summary
private InputFilter[] activeFilters

Active filters (in order).

byteBufferback to summary
private ByteBuffer byteBuffer

The read buffer.

chrback to summary
private byte chr
CLIENT_PREFACE_STARTback to summary
private static final byte[] CLIENT_PREFACE_START
endback to summary
private int end

Pos of the end of the header in the buffer, which is also the start of the body.

filterLibraryback to summary
private InputFilter[] filterLibrary

Filter library.

Note

Filter[Constants.CHUNKED_FILTER] is always the "chunked" filter.

headerBufferSizeback to summary
private final int headerBufferSize

Maximum allowed size of the HTTP request line plus headers plus any leading blank lines.

headerDataback to summary
private final Http11InputBuffer.HeaderParseData headerData
headerParsePosback to summary
private Http11InputBuffer.HeaderParsePosition headerParsePos
headersback to summary
private final MimeHeaders headers

Headers of the associated request.

httpParserback to summary
private final HttpParser httpParser
inputStreamInputBufferback to summary
private InputBuffer inputStreamInputBuffer

Underlying input buffer.

lastActiveFilterback to summary
private int lastActiveFilter

Index of the last active filter.

logback to summary
private static final Log log
parsingHeaderback to summary
private volatile boolean parsingHeader

State.

parsingRequestLineback to summary
private volatile boolean parsingRequestLine
parsingRequestLineEolback to summary
private boolean parsingRequestLineEol
parsingRequestLinePhaseback to summary
private int parsingRequestLinePhase
parsingRequestLineQPosback to summary
private int parsingRequestLineQPos
parsingRequestLineStartback to summary
private int parsingRequestLineStart
prevChrback to summary
private byte prevChr

Parsing state - used for non blocking parsing so that when more data arrives, we can pick up where we left off.

rejectIllegalHeaderback to summary
private final boolean rejectIllegalHeader
requestback to summary
private final Request request

Associated Coyote request.

smback to summary
private static final StringManager sm

The string manager for this package.

socketReadBufferSizeback to summary
private int socketReadBufferSize

Known size of the NioChannel read buffer.

swallowInputback to summary
private boolean swallowInput

Swallow input ? (in the case of an expectation)

wrapperback to summary
private SocketWrapperBase<?> wrapper

Wrapper that provides access to the underlying socket.

Constructor Detail

Http11InputBufferback to summary
public Http11InputBuffer(Request request, int headerBufferSize, boolean rejectIllegalHeader, HttpParser httpParser)

Method Detail

addActiveFilterback to summary
pack-priv void addActiveFilter(InputFilter filter)

Add an input filter to the filter library.

addFilterback to summary
pack-priv void addFilter(InputFilter filter)

Add an input filter to the filter library.

Exceptions
NullPointerException:
if the supplied filter is null
availableback to summary
public int available()

Implements org.apache.coyote.InputBuffer.available.

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

Obtain an estimate of the number of bytes that can be read without blocking. Typically, this will be the number of available bytes known to be buffered.

Returns:int

The number of bytes that can be read without blocking

Annotations
@Override
availableback to summary
pack-priv int available(boolean read)

Available bytes in the buffers for the current request. Note that when requests are pipelined, the data in byteBuffer may relate to the next request rather than this one.

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
endRequestback to summary
pack-priv void endRequest() throws IOException

End request (consumes leftover bytes).

Exceptions
IOException:
an underlying I/O error occurred
expandback to summary
public void expand(int size)

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

Annotations
@Override
fillback to summary
private boolean fill(boolean block) throws IOException

Attempts to read some data into the input buffer.

Returns:boolean

true if more data was added to the input buffer otherwise false

getByteBufferback to summary
public ByteBuffer getByteBuffer()

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

Annotations
@Override
getFiltersback to summary
pack-priv InputFilter[] getFilters()

Get filters.

getLeftoverback to summary
pack-priv ByteBuffer getLeftover()
getParsingRequestLinePhaseback to summary
pack-priv int getParsingRequestLinePhase()
initback to summary
pack-priv void init(SocketWrapperBase<?> socketWrapper)
isChunkingback to summary
pack-priv boolean isChunking()
isFinishedback to summary
pack-priv boolean isFinished()

Has all of the request body been read? There are subtle differences between this and available() > 0 primarily because of having to handle faking non-blocking reads with the blocking IO connector.

nextRequestback to summary
pack-priv void nextRequest()

End processing of current HTTP request.

Note

All bytes of the current request should have been already consumed. This method only resets all the pointers so that we are ready to parse the next HTTP request.

parseHeaderback to summary
private Http11InputBuffer.HeaderParseStatus parseHeader() throws IOException

Parse an HTTP header.

Returns:Http11InputBuffer.HeaderParseStatus

One of HeaderParseStatus#NEED_MORE_DATA, HeaderParseStatus#HAVE_MORE_HEADERS or HeaderParseStatus#DONE.

parseHeadersback to summary
pack-priv boolean parseHeaders() throws IOException

Parse the HTTP headers.

parseInvalidback to summary
private String parseInvalid(int startPos, ByteBuffer buffer)
parseRequestLineback to summary
pack-priv boolean parseRequestLine(boolean keptAlive, int connectionTimeout, int keepAliveTimeout) throws IOException

Read the request line. This function is meant to be used during the HTTP request header parsing. Do NOT attempt to read the request body using it.

Returns:boolean

true if data is properly fed; false if no data is available immediately and thread should be freed

Exceptions
IOException:
If an exception occurs during the underlying socket read operations, or if the given buffer is not big enough to accommodate the whole line.
recycleback to summary
pack-priv void recycle()

Recycle the input buffer. This should be called when closing the connection.

setByteBufferback to summary
public void setByteBuffer(ByteBuffer buffer)

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

Annotations
@Override
setSwallowInputback to summary
pack-priv void setSwallowInput(boolean swallowInput)

Set the swallow input flag.

skipLineback to summary
private Http11InputBuffer.HeaderParseStatus skipLine(boolean deleteHeader) throws IOException
org.apache.coyote.http11 back to summary

private Class Http11InputBuffer.HeaderParseData

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv MessageBytes
headerValue

MB that will store the value of the header.

pack-priv int
lastSignificantChar

When parsing header name: not used (stays as 0).

pack-priv int
lineStart

The first character of the header line.

pack-priv int
realPos

When parsing header name: not used (stays as 0).

pack-priv int
start

When parsing header name: first character of the header.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

headerValueback to summary
pack-priv MessageBytes headerValue

MB that will store the value of the header. It is null while parsing header name and is created after the name has been parsed.

lastSignificantCharback to summary
pack-priv int lastSignificantChar

When parsing header name: not used (stays as 0).
When skipping broken header line: last non-CR/non-LF character.
When parsing header value: position after the last not-LWS character.

lineStartback to summary
pack-priv int lineStart

The first character of the header line.

realPosback to summary
pack-priv int realPos

When parsing header name: not used (stays as 0).
When skipping broken header line: not used (stays as 0).
When parsing header value: starts as the first character after ':'. Then is increased as far as more bytes of the header are harvested. Bytes from buf[pos] are copied to buf[realPos]. Thus the string from [start] to [realPos-1] is the prepared value of the header, with whitespaces removed as needed.

startback to summary
pack-priv int start

When parsing header name: first character of the header.
When skipping broken header line: first character of the header.
When parsing header value: first character after ':'.

Constructor Detail

HeaderParseDataback to summary
private HeaderParseData()

Method Detail

recycleback to summary
public void recycle()
org.apache.coyote.http11 back to summary

private final Enum Http11InputBuffer.HeaderParsePosition

extends Enum<Http11InputBuffer.HeaderParsePosition>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final Http11InputBuffer.HeaderParsePosition
HEADER_MULTI_LINE

Before reading a new line of a header.

public static final Http11InputBuffer.HeaderParsePosition
HEADER_NAME

Reading a header name.

public static final Http11InputBuffer.HeaderParsePosition
HEADER_SKIPLINE

Reading all bytes until the next CRLF.

public static final Http11InputBuffer.HeaderParsePosition
HEADER_START

Start of a new header.

public static final Http11InputBuffer.HeaderParsePosition
HEADER_VALUE

Reading the header value.

public static final Http11InputBuffer.HeaderParsePosition
HEADER_VALUE_START

Skipping whitespace before text of header value starts, either on the first line of header value (just after ':') or on subsequent lines when it is known that subsequent line starts with SP or HT.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Http11InputBuffer.HeaderParsePosition
public static Http11InputBuffer.HeaderParsePosition[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

HEADER_MULTI_LINEback to summary
public static final Http11InputBuffer.HeaderParsePosition HEADER_MULTI_LINE

Before reading a new line of a header. Once the next byte is peeked, the state changes without advancing our position. The state becomes either HEADER_VALUE_START (if that first byte is SP or HT), or HEADER_START (otherwise).

HEADER_NAMEback to summary
public static final Http11InputBuffer.HeaderParsePosition HEADER_NAME

Reading a header name. All characters of header are HTTP_TOKEN_CHAR. Header name is followed by ':'. No whitespace is allowed.
Any non-HTTP_TOKEN_CHAR (this includes any whitespace) encountered before ':' will result in the whole line being ignored.

HEADER_SKIPLINEback to summary
public static final Http11InputBuffer.HeaderParsePosition HEADER_SKIPLINE

Reading all bytes until the next CRLF. The line is being ignored.

HEADER_STARTback to summary
public static final Http11InputBuffer.HeaderParsePosition HEADER_START

Start of a new header. A CRLF here means that there are no more headers. Any other character starts a header name.

HEADER_VALUEback to summary
public static final Http11InputBuffer.HeaderParsePosition HEADER_VALUE

Reading the header value. We are inside the value. Either on the first line or on any subsequent line. We come into this state from HEADER_VALUE_START after the first non-SP/non-HT byte is encountered on the line.

HEADER_VALUE_STARTback to summary
public static final Http11InputBuffer.HeaderParsePosition HEADER_VALUE_START

Skipping whitespace before text of header value starts, either on the first line of header value (just after ':') or on subsequent lines when it is known that subsequent line starts with SP or HT.

Constructor Detail

HeaderParsePositionback to summary
private HeaderParsePosition()

Method Detail

valueOfback to summary
public static Http11InputBuffer.HeaderParsePosition valueOf(String name)
valuesback to summary
public static Http11InputBuffer.HeaderParsePosition[] values()
org.apache.coyote.http11 back to summary

private final Enum Http11InputBuffer.HeaderParseStatus

extends Enum<Http11InputBuffer.HeaderParseStatus>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final Http11InputBuffer.HeaderParseStatus
public static final Http11InputBuffer.HeaderParseStatus
public static final Http11InputBuffer.HeaderParseStatus

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Http11InputBuffer.HeaderParseStatus
public static Http11InputBuffer.HeaderParseStatus[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

DONEback to summary
public static final Http11InputBuffer.HeaderParseStatus DONE
HAVE_MORE_HEADERSback to summary
public static final Http11InputBuffer.HeaderParseStatus HAVE_MORE_HEADERS
NEED_MORE_DATAback to summary
public static final Http11InputBuffer.HeaderParseStatus NEED_MORE_DATA

Constructor Detail

HeaderParseStatusback to summary
private HeaderParseStatus()

Method Detail

valueOfback to summary
public static Http11InputBuffer.HeaderParseStatus valueOf(String name)
valuesback to summary
public static Http11InputBuffer.HeaderParseStatus[] values()
org.apache.coyote.http11 back to summary

private Class Http11InputBuffer.SocketInputBuffer

extends Object
implements InputBuffer
Class Inheritance
All Implemented Interfaces
org.apache.coyote.InputBuffer

This class is an input buffer which will read its data from an input stream.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public int
available()

Implements org.apache.coyote.InputBuffer.available.

Obtain an estimate of the number of bytes that can be read without blocking.

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.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

SocketInputBufferback to summary
private SocketInputBuffer()

Method Detail

availableback to summary
public int available()

Implements org.apache.coyote.InputBuffer.available.

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

Obtain an estimate of the number of bytes that can be read without blocking. Typically, this will be the number of available bytes known to be buffered.

Returns:int

The number of bytes that can be read without blocking

Annotations
@Override
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