org.apache.coyote.http11
Class InternalInputBuffer

java.lang.Object
  extended byorg.apache.coyote.http11.InternalInputBuffer
All Implemented Interfaces:
InputBuffer

public class InternalInputBuffer
extends java.lang.Object
implements InputBuffer

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

Author:
Remy Maucherat

Nested Class Summary
protected  class InternalInputBuffer.InputStreamInputBuffer
          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  char[] ascbuf
          Pointer to the US-ASCII header buffer.
protected  byte[] bodyBuffer
          HTTP body buffer.
protected  byte[] buf
          Pointer to the current read buffer.
protected  InputFilter[] filterLibrary
          Filter library.
protected  char[] headerBuffer
          US-ASCII header buffer.
protected  byte[] headerBuffer1
          HTTP header buffer no 1.
protected  byte[] headerBuffer2
          HTTP header buffer no 2.
protected  MimeHeaders headers
          Headers of the associated request.
protected  java.io.InputStream inputStream
          Underlying input stream.
protected  InputBuffer inputStreamInputBuffer
          Underlying input buffer.
protected  int lastActiveFilter
          Index of the last active filter.
protected  int lastValid
          Last valid byte.
protected  boolean parsingHeader
          State.
protected  int pos
          Position in the buffer.
protected  Request request
          Associated Coyote request.
protected static StringManager sm
          The string manager for this package.
protected  boolean swallowInput
          Swallow input ?
 
Constructor Summary
InternalInputBuffer(Request request)
          Default constructor.
InternalInputBuffer(Request request, int headerBufferSize)
          Alternate constructor.
 
Method Summary
 void addActiveFilter(InputFilter filter)
          Add an input filter to the filter library.
 void addFilter(InputFilter filter)
          Add an input filter to the filter library.
 void clearFilters()
          Clear filters.
 int doRead(ByteChunk chunk, Request req)
          Read some bytes.
 void endRequest()
          End request (consumes leftover bytes).
protected  boolean fill()
          Fill the internal buffer using data from the undelying input stream.
 InputFilter[] getFilters()
          Get filters.
 java.io.InputStream getInputStream()
          Get the underlying socket input stream.
 void nextRequest()
          End processing of current HTTP request.
 boolean parseHeader()
          Parse an HTTP header.
 void parseHeaders()
          Parse the HTTP headers.
 void parseRequestLine()
          Read the request line.
 void recycle()
          Recycle the input buffer.
 void setInputStream(java.io.InputStream inputStream)
          Set the underlying socket input stream.
 void setSwallowInput(boolean swallowInput)
          Set the swallow input flag.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sm

protected static StringManager sm
The string manager for this package.


request

protected Request request
Associated Coyote request.


headers

protected MimeHeaders headers
Headers of the associated request.


parsingHeader

protected boolean parsingHeader
State.


swallowInput

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


buf

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


ascbuf

protected char[] ascbuf
Pointer to the US-ASCII header buffer.


lastValid

protected int lastValid
Last valid byte.


pos

protected int pos
Position in the buffer.


headerBuffer1

protected byte[] headerBuffer1
HTTP header buffer no 1.


headerBuffer2

protected byte[] headerBuffer2
HTTP header buffer no 2.


bodyBuffer

protected byte[] bodyBuffer
HTTP body buffer.


headerBuffer

protected char[] headerBuffer
US-ASCII header buffer.


inputStream

protected java.io.InputStream inputStream
Underlying input stream.


inputStreamInputBuffer

protected InputBuffer inputStreamInputBuffer
Underlying input buffer.


filterLibrary

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


activeFilters

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


lastActiveFilter

protected int lastActiveFilter
Index of the last active filter.

Constructor Detail

InternalInputBuffer

public InternalInputBuffer(Request request)
Default constructor.


InternalInputBuffer

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

Method Detail

setInputStream

public void setInputStream(java.io.InputStream inputStream)
Set the underlying socket input stream.


getInputStream

public java.io.InputStream getInputStream()
Get the underlying socket input stream.


addFilter

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


getFilters

public InputFilter[] getFilters()
Get filters.


clearFilters

public void clearFilters()
Clear filters.


addActiveFilter

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


setSwallowInput

public void setSwallowInput(boolean swallowInput)
Set the swallow input flag.


recycle

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


nextRequest

public void nextRequest()
                 throws java.io.IOException
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.

Throws:
java.io.IOException

endRequest

public void endRequest()
                throws java.io.IOException
End request (consumes leftover bytes).

Throws:
java.io.IOException - an undelying I/O error occured

parseRequestLine

public void parseRequestLine()
                      throws java.io.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.

Throws:
java.io.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.

parseHeaders

public void parseHeaders()
                  throws java.io.IOException
Parse the HTTP headers.

Throws:
java.io.IOException

parseHeader

public boolean parseHeader()
                    throws java.io.IOException
Parse an HTTP header.

Returns:
false after reading a blank line (which indicates that the HTTP header parsing is done
Throws:
java.io.IOException

doRead

public int doRead(ByteChunk chunk,
                  Request req)
           throws java.io.IOException
Read some bytes.

Specified by:
doRead in interface InputBuffer
Throws:
java.io.IOException

fill

protected boolean fill()
                throws java.io.IOException
Fill the internal buffer using data from the undelying input stream.

Returns:
false if at end of stream
Throws:
java.io.IOException


Copyright © 2000-2012 Apache Software Foundation. All Rights Reserved.