org.apache.coyote.http11

Class InternalNioInputBuffer

public class InternalNioInputBuffer extends Object implements InputBuffer

Implementation of InputBuffer which provides HTTP request header parsing as well as transfer decoding.

Author: Remy Maucherat Filip Hanik

Nested Class Summary
static classInternalNioInputBuffer.HeaderParseData
protected classInternalNioInputBuffer.SocketInputBuffer
This class is an input buffer which will read its data from an input stream.
Field Summary
protected InputFilter[]activeFilters
Active filters (in order).
protected byte[]buf
Pointer to the current read buffer.
protected intend
Pos of the end of the header in the buffer, which is also the start of the body.
protected InputFilter[]filterLibrary
Filter library.
protected InternalNioInputBuffer.HeaderParseDataheaderData
protected InternalNioInputBuffer.HeaderParsePositionheaderParsePos
protected MimeHeadersheaders
Headers of the associated request.
protected InputBufferinputStreamInputBuffer
Underlying input buffer.
protected intlastActiveFilter
Index of the last active filter.
protected intlastValid
Last valid byte.
protected booleanparsingHeader
Parsing state - used for non blocking parsing so that when more data arrives, we can pick up where we left off.
protected booleanparsingRequestLine
protected booleanparsingRequestLineEol
protected intparsingRequestLinePhase
protected intparsingRequestLineQPos
protected intparsingRequestLineStart
protected NioSelectorPoolpool
Selector pool, for blocking reads and blocking writes
protected intpos
Position in the buffer.
protected Requestrequest
Associated Coyote request.
protected static StringManagersm
The string manager for this package.
protected NioChannelsocket
Underlying socket.
protected booleanswallowInput
Swallow input ?
Constructor Summary
InternalNioInputBuffer(Request request, int headerBufferSize)
Alternate constructor.
Method Summary
voidaddActiveFilter(InputFilter filter)
Add an input filter to the filter library.
voidaddFilter(InputFilter filter)
Add an input filter to the filter library.
intavailable()
Available bytes (note that due to encoding, this may not correspond )
voidclearFilters()
Clear filters.
intdoRead(ByteChunk chunk, Request req)
Read some bytes.
voidendRequest()
End request (consumes leftover bytes).
protected booleanfill(boolean timeout, boolean block)
Fill the internal buffer using data from the undelying input stream.
InputFilter[]getFilters()
Get filters.
NioSelectorPoolgetSelectorPool()
NioChannelgetSocket()
Get the underlying socket input stream.
booleanisReadable()
Returns true if there are bytes available from the socket layer
intnbRead()
Issues a non blocking read
voidnextRequest()
End processing of current HTTP request.
InternalNioInputBuffer.HeaderParseStatusparseHeader()
Parse an HTTP header.
booleanparseHeaders()
Parse the HTTP headers.
booleanparseRequestLine(boolean useAvailableData)
Read the request line.
voidrecycle()
Recycle the input buffer.
voidsetSelectorPool(NioSelectorPool pool)
voidsetSocket(NioChannel socket)
Set the underlying socket.
voidsetSwallowInput(boolean swallowInput)
Set the swallow input flag.

Field Detail

activeFilters

protected InputFilter[] activeFilters
Active filters (in order).

buf

protected byte[] buf
Pointer to the current read buffer.

end

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

filterLibrary

protected InputFilter[] filterLibrary
Filter library. Note: Filter[0] is always the "chunked" filter.

headerData

protected InternalNioInputBuffer.HeaderParseData headerData

headerParsePos

protected InternalNioInputBuffer.HeaderParsePosition headerParsePos

headers

protected MimeHeaders headers
Headers of the associated request.

inputStreamInputBuffer

protected InputBuffer inputStreamInputBuffer
Underlying input buffer.

lastActiveFilter

protected int lastActiveFilter
Index of the last active filter.

lastValid

protected int lastValid
Last valid byte.

parsingHeader

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

parsingRequestLine

protected boolean parsingRequestLine

parsingRequestLineEol

protected boolean parsingRequestLineEol

parsingRequestLinePhase

protected int parsingRequestLinePhase

parsingRequestLineQPos

protected int parsingRequestLineQPos

parsingRequestLineStart

protected int parsingRequestLineStart

pool

protected NioSelectorPool pool
Selector pool, for blocking reads and blocking writes

pos

protected int pos
Position in the buffer.

request

protected Request request
Associated Coyote request.

sm

protected static StringManager sm
The string manager for this package.

socket

protected NioChannel socket
Underlying socket.

swallowInput

protected boolean swallowInput
Swallow input ? (in the case of an expectation)

Constructor Detail

InternalNioInputBuffer

public InternalNioInputBuffer(Request request, int headerBufferSize)
Alternate constructor.

Method Detail

addActiveFilter

public void addActiveFilter(InputFilter filter)
Add an input filter to the filter library.

addFilter

public void addFilter(InputFilter filter)
Add an input filter to the filter library.

available

public int available()
Available bytes (note that due to encoding, this may not correspond )

clearFilters

public void clearFilters()
Clear filters.

doRead

public int doRead(ByteChunk chunk, Request req)
Read some bytes.

endRequest

public void endRequest()
End request (consumes leftover bytes).

Throws: IOException an undelying I/O error occured

fill

protected boolean fill(boolean timeout, boolean block)
Fill the internal buffer using data from the undelying input stream.

Returns: false if at end of stream

getFilters

public InputFilter[] getFilters()
Get filters.

getSelectorPool

public NioSelectorPool getSelectorPool()

getSocket

public NioChannel getSocket()
Get the underlying socket input stream.

isReadable

public boolean isReadable()
Returns true if there are bytes available from the socket layer

Returns: boolean

Throws: IOException

nbRead

public int nbRead()
Issues a non blocking read

Returns: int

Throws: IOException

nextRequest

public 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.

parseHeader

public InternalNioInputBuffer.HeaderParseStatus parseHeader()
Parse an HTTP header.

Returns: false after reading a blank line (which indicates that the HTTP header parsing is done

parseHeaders

public boolean parseHeaders()
Parse the HTTP headers.

parseRequestLine

public boolean parseRequestLine(boolean useAvailableData)
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: true if data is properly fed; false if no data is available immediately and thread should be freed

Throws: IOException If an exception occurs during the underlying socket read operations, or if the given buffer is not big enough to accomodate the whole line.

recycle

public void recycle()
Recycle the input buffer. This should be called when closing the connection.

setSelectorPool

public void setSelectorPool(NioSelectorPool pool)

setSocket

public void setSocket(NioChannel socket)
Set the underlying socket.

setSwallowInput

public void setSwallowInput(boolean swallowInput)
Set the swallow input flag.
Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.