Top Inners Fields Constructors Methods
org.mortbay.jetty

public Class HttpParser

extends Object
implements Parser
Class Inheritance
All Implemented Interfaces
org.mortbay.jetty.Parser
Imports
java.io.IOException, javax.servlet.ServletInputStream, javax.servlet.http.HttpServletResponse, org.mortbay.io.AbstractBuffer, .Buffer, .BufferUtil, .Buffers, .ByteArrayBuffer, .EndPoint, .View, .BufferCache.CachedBuffer, org.mortbay.log.Log, org.mortbay.util.StringUtil

Author
gregw

Nested and Inner Type Summary

Modifier and TypeClass and Description
public abstract static class
public static class

Field Summary

Modifier and TypeField and Description
private Buffer
private Buffer
private Buffers
private BufferCache.CachedBuffer
protected int
protected int
private int
protected long
protected long
private View
private EndPoint
protected byte
private boolean
private HttpParser.EventHandler
private Buffer
private int
private HttpParser.Input
protected int
private String
private int
protected int
private View.CaseInsensitive
private View.CaseInsensitive
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int

Constructor Summary

AccessConstructor and Description
public
HttpParser(Buffer buffer, HttpParser.EventHandler handler)

Constructor.

public
HttpParser(Buffers buffers, EndPoint endp, HttpParser.EventHandler handler, int
size in bytes of header buffer
headerBufferSize
,
int
size in bytes of content buffer
contentBufferSize
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
public long
fill()

fill the buffers from the endpoint

public Buffer
public long
public Buffer
public int
public boolean
public boolean
public boolean
public boolean
public boolean
public boolean
public boolean
isState(int state)

public void
parse()

Parse until END state.

public long
parseAvailable()

Implements org.mortbay.jetty.Parser.parseAvailable.

Parse until END state.
public long

Returns:

number of bytes filled from endpoint or -1 if fill never called.
parseNext
()

Parse until next Event.

public void
reset(boolean returnBuffers)

Implements org.mortbay.jetty.Parser.reset.

public void
setForceContentBuffer(boolean
True if a new buffer will be forced to be used for content and the header buffer will not be used.
force
)

public void
setState(int state)

public void
skipCRLF()

Skip any CRLFs in buffers

public String
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

_bodyback to summary
private Buffer _body
_bufferback to summary
private Buffer _buffer
_buffersback to summary
private Buffers _buffers
_cachedback to summary
private BufferCache.CachedBuffer _cached
_chunkLengthback to summary
protected int _chunkLength
_chunkPositionback to summary
protected int _chunkPosition
_contentBufferSizeback to summary
private int _contentBufferSize
_contentLengthback to summary
protected long _contentLength
_contentPositionback to summary
protected long _contentPosition
_contentViewback to summary
private View _contentView
_endpback to summary
private EndPoint _endp
_eolback to summary
protected byte _eol
_forceContentBufferback to summary
private boolean _forceContentBuffer
_handlerback to summary
private HttpParser.EventHandler _handler
_headerback to summary
private Buffer _header
_headerBufferSizeback to summary
private int _headerBufferSize
_inputback to summary
private HttpParser.Input _input
_lengthback to summary
protected int _length
_multiLineValueback to summary
private String _multiLineValue
_responseStatusback to summary
private int _responseStatus
_stateback to summary
protected int _state
_tok0back to summary
private View.CaseInsensitive _tok0
_tok1back to summary
private View.CaseInsensitive _tok1
STATE_CHUNKback to summary
public static final int STATE_CHUNK
STATE_CHUNK_PARAMSback to summary
public static final int STATE_CHUNK_PARAMS
STATE_CHUNK_SIZEback to summary
public static final int STATE_CHUNK_SIZE
STATE_CHUNKED_CONTENTback to summary
public static final int STATE_CHUNKED_CONTENT
STATE_CONTENTback to summary
public static final int STATE_CONTENT
STATE_ENDback to summary
public static final int STATE_END
STATE_END0back to summary
public static final int STATE_END0
STATE_END1back to summary
public static final int STATE_END1
STATE_EOF_CONTENTback to summary
public static final int STATE_EOF_CONTENT
STATE_FIELD0back to summary
public static final int STATE_FIELD0
STATE_FIELD1back to summary
public static final int STATE_FIELD1
STATE_FIELD2back to summary
public static final int STATE_FIELD2
STATE_HEADERback to summary
public static final int STATE_HEADER
STATE_HEADER_IN_NAMEback to summary
public static final int STATE_HEADER_IN_NAME
STATE_HEADER_IN_VALUEback to summary
public static final int STATE_HEADER_IN_VALUE
STATE_HEADER_NAMEback to summary
public static final int STATE_HEADER_NAME
STATE_HEADER_VALUEback to summary
public static final int STATE_HEADER_VALUE
STATE_SPACE1back to summary
public static final int STATE_SPACE1
STATE_SPACE2back to summary
public static final int STATE_SPACE2
STATE_STARTback to summary
public static final int STATE_START

Constructor Detail

HttpParserback to summary
public HttpParser(Buffer buffer, HttpParser.EventHandler handler)

Constructor.

HttpParserback to summary
public HttpParser(Buffers buffers, EndPoint endp, HttpParser.EventHandler handler, int headerBufferSize, int contentBufferSize)

Constructor.

Parameters
headerBufferSize:int

size in bytes of header buffer

contentBufferSize:int

size in bytes of content buffer

Method Detail

fillback to summary
public long fill() throws IOException

fill the buffers from the endpoint

getBodyBufferback to summary
public Buffer getBodyBuffer()
getContentLengthback to summary
public long getContentLength()
getHeaderBufferback to summary
public Buffer getHeaderBuffer()
getStateback to summary
public int getState()
inContentStateback to summary
public boolean inContentState()
inHeaderStateback to summary
public boolean inHeaderState()
isChunkingback to summary
public boolean isChunking()
isCompleteback to summary
public boolean isComplete()

Implements org.mortbay.jetty.Parser.isComplete.

isIdleback to summary
public boolean isIdle()

Implements org.mortbay.jetty.Parser.isIdle.

isMoreInBufferback to summary
public boolean isMoreInBuffer() throws IOException

Implements org.mortbay.jetty.Parser.isMoreInBuffer.

isStateback to summary
public boolean isState(int state)
parseback to summary
public void parse() throws IOException

Parse until END state. If the parser is already in the END state, then it is reset and re-parsed.

Exceptions
IllegalStateException:
If the buffers have already been partially parsed.
parseAvailableback to summary
public long parseAvailable() throws IOException

Implements org.mortbay.jetty.Parser.parseAvailable.

Parse until END state. This method will parse any remaining content in the current buffer. It does not care about the current state of the parser.

See Also
parse, parseNext
parseNextback to summary
public long parseNext() throws IOException

Parse until next Event.

Returns:long

number of bytes filled from endpoint or -1 if fill never called.

resetback to summary
public void reset(boolean returnBuffers)

Implements org.mortbay.jetty.Parser.reset.

setForceContentBufferback to summary
public void setForceContentBuffer(boolean force)
Parameters
force:boolean

True if a new buffer will be forced to be used for content and the header buffer will not be used.

setStateback to summary
public void setState(int state)
skipCRLFback to summary
public void skipCRLF()

Skip any CRLFs in buffers

toStringback to summary
public String toString(Buffer buf)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

org.mortbay.jetty back to summary

public abstract Class HttpParser.EventHandler

extends Object
Class Inheritance
Known Direct Subclasses
org.mortbay.jetty.HttpConnection.RequestHandler

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public abstract void
public void
public void
messageComplete(long contextLength)

public void
parsedHeader(Buffer name, Buffer value)

This is the method called by parser when a HTTP Header name and value is found

public abstract void
startRequest(Buffer method, Buffer url, Buffer version)

This is the method called by parser when the HTTP request line is parsed

public abstract void
startResponse(Buffer version, int status, Buffer reason)

This is the method called by parser when the HTTP request line is parsed

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

EventHandlerback to summary
public EventHandler()

Method Detail

contentback to summary
public abstract void content(Buffer ref) throws IOException
headerCompleteback to summary
public void headerComplete() throws IOException
messageCompleteback to summary
public void messageComplete(long contextLength) throws IOException
parsedHeaderback to summary
public void parsedHeader(Buffer name, Buffer value) throws IOException

This is the method called by parser when a HTTP Header name and value is found

startRequestback to summary
public abstract void startRequest(Buffer method, Buffer url, Buffer version) throws IOException

This is the method called by parser when the HTTP request line is parsed

startResponseback to summary
public abstract void startResponse(Buffer version, int status, Buffer reason) throws IOException

This is the method called by parser when the HTTP request line is parsed

org.mortbay.jetty back to summary

public Class HttpParser.Input

extends ServletInputStream
Class Inheritance

Field Summary

Modifier and TypeField and Description
protected Buffer
protected EndPoint
protected long
protected HttpParser

Constructor Summary

AccessConstructor and Description
public
Input(HttpParser parser, long maxIdleTime)

Method Summary

Modifier and TypeMethod and Description
public int
available()

Overrides java.io.InputStream.available.

Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking, which may be 0, or 0 when end of stream is detected.
private boolean
public int
read()

Implements abstract java.io.InputStream.read.

Reads the next byte of data from the input stream.
public int
read(byte[]
the buffer into which the data is read.
b
,
int
the start offset in array b at which the data is written.
off
,
int
the maximum number of bytes to read.
len
)

Overrides java.io.InputStream.read.

Reads up to len bytes of data from the input stream into an array of bytes.
Inherited from javax.servlet.ServletInputStream:
isFinishedisReadyreadLinesetReadListener

Field Detail

_contentViewback to summary
protected Buffer _contentView
_endpback to summary
protected EndPoint _endp
_maxIdleTimeback to summary
protected long _maxIdleTime
_parserback to summary
protected HttpParser _parser

Constructor Detail

Inputback to summary
public Input(HttpParser parser, long maxIdleTime)

Method Detail

availableback to summary
public int available() throws IOException

Overrides java.io.InputStream.available.

Doc from java.io.InputStream.available.

Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking, which may be 0, or 0 when end of stream is detected. The read might be on the same thread or another thread. A single read or skip of this many bytes will not block, but may read or skip fewer bytes.

Note that while some implementations of InputStream will return the total number of bytes in the stream, many will not. It is never correct to use the return value of this method to allocate a buffer intended to hold all data in this stream.

A subclass's implementation of this method may choose to throw an IOException if this input stream has been closed by invoking the close() method.

Returns:int

an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking or 0 when it reaches the end of the input stream.

Exceptions
IOException:
if an I/O error occurs.
blockForContentback to summary
private boolean blockForContent() throws IOException
readback to summary
public int read() throws IOException

Implements abstract java.io.InputStream.read.

Doc from java.io.InputStream.read.

Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

Returns:int

the next byte of data, or -1 if the end of the stream is reached.

Exceptions
IOException:
if an I/O error occurs.
readback to summary
public int read(byte[] b, int off, int len) throws IOException

Overrides java.io.InputStream.read.

Doc from java.io.InputStream.read.

Reads up to len bytes of data from the input stream into an array of bytes. An attempt is made to read as many as len bytes, but a smaller number may be read. The number of bytes actually read is returned as an integer.

This method blocks until input data is available, end of file is detected, or an exception is thrown.

If len is zero, then no bytes are read and 0 is returned; otherwise, there is an attempt to read at least one byte. If no byte is available because the stream is at end of file, the value -1 is returned; otherwise, at least one byte is read and stored into b.

The first byte read is stored into element b[off], the next one into b[off+1], and so on. The number of bytes read is, at most, equal to len. Let k be the number of bytes actually read; these bytes will be stored in elements b[off] through b[off+k-1], leaving elements b[off+k] through b[off+len-1] unaffected.

In every case, elements b[0] through b[off-1] and elements b[off+len] through b[b.length-1] are unaffected.

Parameters
b:byte[]

the buffer into which the data is read.

off:int

the start offset in array b at which the data is written.

len:int

the maximum number of bytes to read.

Returns:int

the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.

Exceptions
IOException:
If the first byte cannot be read for any reason other than end of file, or if the input stream has been closed, or if some other I/O error occurs.