com.caucho.server.http
Class HttpRequest

java.lang.Object
  extended by com.caucho.server.http.AbstractHttpRequest
      extended by com.caucho.server.http.HttpRequest
All Implemented Interfaces:
ProtocolConnection, SecurityContextProvider
Direct Known Subclasses:
CompileRequest, SocketPolicyRequest

public class HttpRequest
extends AbstractHttpRequest
implements ProtocolConnection

Handles a new request from an HTTP connection.


Field Summary
static int HTTP_0_9
           
static int HTTP_1_0
           
static int HTTP_1_1
           
 
Fields inherited from class com.caucho.server.http.AbstractHttpRequest
_headerCodes, _hostHeader, JSP_EXCEPTION, SHUTDOWN
 
Constructor Summary
HttpRequest(Server server, SocketLink conn)
          Creates a new HttpRequest.
 
Method Summary
protected  boolean checkLogin()
           
 HttpResponse createResponse()
           
protected  java.lang.String dbgId()
           
 java.lang.String findSessionIdFromConnection()
          For SSL connections, use the SSL identifier.
 void finishRequest()
          Cleans up at the end of the invocation
 java.lang.String getHeader(java.lang.String key)
          Returns the header.
 CharSegment getHeaderBuffer(char[] testBuf, int length)
          Returns the matching header.
 CharSegment getHeaderBuffer(java.lang.String key)
          Returns the header value for the key, returned as a CharSegment.
 void getHeaderBuffers(java.lang.String key, java.util.ArrayList<CharSegment> values)
          Fills an ArrayList with the header values matching the key.
 CharSegment getHeaderKey(int index)
          Returns the header key
 java.util.Enumeration<java.lang.String> getHeaderNames()
          Returns an enumeration of all the header keys.
 java.util.Enumeration<java.lang.String> getHeaders(java.lang.String key)
          Return an enumeration of headers matching a key.
 int getHeaderSize()
          Returns the number of headers.
 CharSegment getHeaderValue(int index)
          Returns the header value
protected  java.lang.CharSequence getHost()
          Returns the virtual host of the request
 java.lang.String getMethod()
          Returns the HTTP method (GET, POST, HEAD, etc.)
 CharSegment getMethodBuffer()
          Returns a buffer containing the request method.
 java.lang.String getProtocol()
          Returns the protocol.
 CharSegment getProtocolBuffer()
          Returns a char segment containing the protocol.
 ReadStream getRawInput()
          Returns the raw input stream.
 byte[] getUriBuffer()
          Returns the byte buffer containing the request URI
 int getUriLength()
          Returns the length of the request URI
 boolean handleRequest()
          Handles a new HTTP request.
 boolean hasRequest()
          Returns true if the request exists
protected  void initAttributes(HttpServletRequestImpl request)
          Initialize any special attributes.
 boolean initStream(ReadStream readStream, ReadStream rawRead)
          Returns a stream for reading POST data.
 boolean isTop()
          Returns true for the top-level request, but false for any include() or forward()
 boolean isWaitForRead()
          Return true if the request waits for a read before beginning.
 void setHeader(java.lang.String key, java.lang.String value)
          Adds a new header.
protected  void skip()
           
 SocketLinkDuplexController startDuplex(SocketLinkDuplexListener handler)
          Upgrade to duplex
protected  void startRequest(HttpBufferStore httpBuffer)
          Clear the request variables in preparation for a new request.
 java.lang.String toString()
           
 
Methods inherited from class com.caucho.server.http.AbstractHttpRequest
addHeaderInt, buildInvocation, cleanup, clearRequest, clientDisconnect, finishInvocation, getAbstractHttpResponse, getAvailable, getCharacterEncoding, getCharBuffer, getConnection, getConnectionId, getContentLength, getContentType, getContentTypeBuffer, getCookies, getDateHeader, getErrorManager, getForm, getFormParser, getInputStream, getIntHeader, getInvocation, getInvocationServer, getLocale, getLocales, getLocalHost, getLocalPort, getLogBuffer, getLongContentLength, getProtocolRequestURL, getRawRead, getRawReadBuffer, getRawWrite, getReader, getReadStream, getRemoteAddr, getRemoteHost, getRemotePort, getRequestFacade, getRequestURI, getRequestURL, getResponse, getResponseFacade, getScheme, getServer, getServerName, getServerPort, getStartTime, getStream, getStream, getUserPrincipal, getWebApp, handleConnectionClose, handleResume, init, isCometActive, isConnectionClosed, isDuplex, isIgnoreClientDisconnect, isKeepalive, isSecure, isSuspend, isTransportSecure, isUserInRole, killKeepalive, onCloseConnection, onStartConnection, printRemoteAddr, restartServer, runAs, sendRequestError, setCharacterEncoding, setContentLength, shutdown, startInvocation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.caucho.network.listen.ProtocolConnection
getProtocolRequestURL, handleResume, init, onCloseConnection, onStartConnection
 

Field Detail

HTTP_0_9

public static final int HTTP_0_9
See Also:
Constant Field Values

HTTP_1_0

public static final int HTTP_1_0
See Also:
Constant Field Values

HTTP_1_1

public static final int HTTP_1_1
See Also:
Constant Field Values
Constructor Detail

HttpRequest

public HttpRequest(Server server,
                   SocketLink conn)
Creates a new HttpRequest. New connections reuse the request.

Parameters:
server - the owning server.
Method Detail

createResponse

public HttpResponse createResponse()
Specified by:
createResponse in class AbstractHttpRequest

isWaitForRead

public final boolean isWaitForRead()
Return true if the request waits for a read before beginning.

Specified by:
isWaitForRead in interface ProtocolConnection

hasRequest

public boolean hasRequest()
Returns true if the request exists

Overrides:
hasRequest in class AbstractHttpRequest

isTop

public boolean isTop()
Returns true for the top-level request, but false for any include() or forward()


checkLogin

protected boolean checkLogin()

getMethodBuffer

public CharSegment getMethodBuffer()
Returns a buffer containing the request method.


getMethod

public java.lang.String getMethod()
Returns the HTTP method (GET, POST, HEAD, etc.)

Specified by:
getMethod in class AbstractHttpRequest

getHost

protected java.lang.CharSequence getHost()
Returns the virtual host of the request

Overrides:
getHost in class AbstractHttpRequest

getUriBuffer

public byte[] getUriBuffer()
Returns the byte buffer containing the request URI

Specified by:
getUriBuffer in class AbstractHttpRequest

getUriLength

public int getUriLength()
Returns the length of the request URI

Specified by:
getUriLength in class AbstractHttpRequest

getProtocol

public java.lang.String getProtocol()
Returns the protocol.

Specified by:
getProtocol in class AbstractHttpRequest

getProtocolBuffer

public CharSegment getProtocolBuffer()
Returns a char segment containing the protocol.


getHeader

public java.lang.String getHeader(java.lang.String key)
Returns the header.

Specified by:
getHeader in class AbstractHttpRequest
Parameters:
key - the header key

getHeaderSize

public int getHeaderSize()
Returns the number of headers.

Overrides:
getHeaderSize in class AbstractHttpRequest

getHeaderKey

public CharSegment getHeaderKey(int index)
Returns the header key

Overrides:
getHeaderKey in class AbstractHttpRequest

getHeaderValue

public CharSegment getHeaderValue(int index)
Returns the header value

Overrides:
getHeaderValue in class AbstractHttpRequest

getHeaderBuffer

public CharSegment getHeaderBuffer(char[] testBuf,
                                   int length)
Returns the matching header.

Parameters:
testBuf - header key
length - length of the key.

getHeaderBuffer

public CharSegment getHeaderBuffer(java.lang.String key)
Returns the header value for the key, returned as a CharSegment.

Overrides:
getHeaderBuffer in class AbstractHttpRequest
Parameters:
key - the header name

getHeaderBuffers

public void getHeaderBuffers(java.lang.String key,
                             java.util.ArrayList<CharSegment> values)
Fills an ArrayList with the header values matching the key.

Overrides:
getHeaderBuffers in class AbstractHttpRequest
Parameters:
values - ArrayList which will contain the maching values.
key - the header key to select.

getHeaders

public java.util.Enumeration<java.lang.String> getHeaders(java.lang.String key)
Return an enumeration of headers matching a key.

Overrides:
getHeaders in class AbstractHttpRequest
Parameters:
key - the header key to match.
Returns:
the enumeration of the headers.

getHeaderNames

public java.util.Enumeration<java.lang.String> getHeaderNames()
Returns an enumeration of all the header keys.

Specified by:
getHeaderNames in class AbstractHttpRequest

setHeader

public void setHeader(java.lang.String key,
                      java.lang.String value)
Adds a new header. Used only by the caching to simulate If-Modified-Since.

Overrides:
setHeader in class AbstractHttpRequest
Parameters:
key - the key of the new header
value - the value for the new header

initAttributes

protected void initAttributes(HttpServletRequestImpl request)
Initialize any special attributes.

Overrides:
initAttributes in class AbstractHttpRequest

findSessionIdFromConnection

public java.lang.String findSessionIdFromConnection()
For SSL connections, use the SSL identifier.

Overrides:
findSessionIdFromConnection in class AbstractHttpRequest

initStream

public boolean initStream(ReadStream readStream,
                          ReadStream rawRead)
                   throws java.io.IOException
Returns a stream for reading POST data.

Specified by:
initStream in class AbstractHttpRequest
Throws:
java.io.IOException

skip

protected void skip()
             throws java.io.IOException
Overrides:
skip in class AbstractHttpRequest
Throws:
java.io.IOException

getRawInput

public ReadStream getRawInput()
Returns the raw input stream.

Overrides:
getRawInput in class AbstractHttpRequest

handleRequest

public boolean handleRequest()
                      throws java.io.IOException
Handles a new HTTP request.

Note: ClientDisconnectException must be rethrown to the caller.

Specified by:
handleRequest in interface ProtocolConnection
Returns:
true if the connection should stay open (keepalive)
Throws:
java.io.IOException

startRequest

protected void startRequest(HttpBufferStore httpBuffer)
                     throws java.io.IOException
Clear the request variables in preparation for a new request.

Overrides:
startRequest in class AbstractHttpRequest
Parameters:
s - the read stream for the request
Throws:
java.io.IOException

startDuplex

public SocketLinkDuplexController startDuplex(SocketLinkDuplexListener handler)
Upgrade to duplex

Overrides:
startDuplex in class AbstractHttpRequest

finishRequest

public void finishRequest()
                   throws java.io.IOException
Cleans up at the end of the invocation

Overrides:
finishRequest in class AbstractHttpRequest
Throws:
java.io.IOException

dbgId

protected java.lang.String dbgId()
Overrides:
dbgId in class AbstractHttpRequest

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object