public final class Request
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
Request.Method
The HTTP methods.
|
| Modifier and Type | Field and Description |
|---|---|
<any> |
attributes
An immutable map of attributes.
|
ByteString |
body
The request body.
|
boolean |
caseSensitiveParameters
If the request has parameters, are they case-sensitive?
|
static java.lang.String |
FORM_ENCODED_CONTENT_TYPE
The expected value for a form encoded header:
application/x-www-form-urlencoded. |
<any> |
headers
An immutable map of headers.
|
Request.Method |
method
The request method.
|
<any> |
parameters
An immutable map of parameters.
|
static java.lang.String |
REMOTE_ADDR
The name of an attribute that may hold the remote address.
|
java.net.URI |
uri
The request URI.
|
| Modifier and Type | Method and Description |
|---|---|
Request |
addHeaders(java.util.Collection<Header> headers)
Adds headers to the existing headers, replacing any that are duplicated.
|
static byte[] |
bodyFromInputStream(java.io.InputStream is,
int maxBytesRead)
Reads the request body from an input stream.
|
ByteString |
getBody()
Gets the request body, if any.
|
java.lang.String |
getCharset(java.lang.String defaultCharset)
Gets the charset specified with the request
Content-Type header, if any. |
java.lang.String |
getContentType()
Gets the value of the
Content-Type header. |
Header |
getHeader(java.lang.String name)
Gets a header.
|
java.util.Collection<Header> |
getHeaders()
Gets all headers.
|
java.lang.String |
getHeaderValue(java.lang.String name)
Gets the first header value.
|
<any> |
getHeaderValueList(java.lang.String name)
Gets an immutable list of values for a header.
|
java.lang.String[] |
getHeaderValues(java.lang.String name)
Gets all values for a header.
|
static java.lang.String |
getHostURL(java.lang.String uri)
Gets a URL for the host portion of a URI without decoding.
|
Request.Method |
getMethod()
Gets the HTTP method.
|
java.util.Collection<Parameter> |
getParameters()
Gets all parameters.
|
java.lang.String |
getParameterValue(java.lang.String name)
Gets the first parameter value.
|
<any> |
getParameterValueList(java.lang.String name)
Gets an immutable list of values for a parameter.
|
java.lang.String[] |
getParameterValues(java.lang.String name)
Gets all values for a parameter.
|
java.util.List<java.lang.String> |
getPathComponents()
Gets the components of the path (separated by '/').
|
static java.util.List<java.lang.String> |
getPathComponents(java.lang.String uri)
Gets the components of the path (separated by '/').
|
java.lang.String |
getQueryString()
Gets the decoded query string.
|
java.lang.String |
getRawQueryString()
Gets the raw query string, without decoding.
|
java.lang.String |
getRemoteAddr()
Gets the IP address of the client that sent the request.
|
java.lang.String |
getRequestPath()
Gets the path component of the request URI.
|
static java.lang.String |
getRequestPath(java.lang.String uri)
Gets the path component of a URI.
|
java.lang.String |
getServerName()
Gets the server name (as specified in the
Host header. |
java.net.URI |
getURI()
Gets the URI.
|
boolean |
isFormEncoded()
Determine if the request is encoded as a form
application/x-www-form-urlencoded |
static java.util.Map<java.lang.String,Parameter> |
parseParameters(java.lang.String queryString)
Parse parameters from a query string.
|
static java.util.Map<java.lang.String,Parameter> |
parseParameters(java.lang.String queryString,
boolean caseSensitiveNames)
Parse parameters from a query string.
|
static java.util.Map<java.lang.String,Parameter> |
parseParametersPreserveNameCase(java.lang.String queryString)
Parse parameters from a query string, preserving case in parameter names.
|
java.lang.String |
toString() |
public static final java.lang.String FORM_ENCODED_CONTENT_TYPE
application/x-www-form-urlencoded.public static final java.lang.String REMOTE_ADDR
public final Request.Method method
public final java.net.URI uri
public final <any> headers
Keys are lower-cased.
public final <any> parameters
If caseSensitiveParameters == false,
map keys are lower-cased.
public final <any> attributes
public final ByteString body
public final boolean caseSensitiveParameters
public Request.Method getMethod()
public java.lang.String getQueryString()
null if none.public java.lang.String getRawQueryString()
null if none.public java.lang.String getRequestPath()
Path always begins with '/' and is never null.
public static final java.lang.String getRequestPath(java.lang.String uri)
throws InvalidURIException
Path always begins with '/' and is never null.
Components are decoded.
uri - The URI.InvalidURIException - if URI is invalid.public static final java.lang.String getHostURL(java.lang.String uri)
throws InvalidURIException
Includes the protocol, if specified. Never ends with '/'.
uri - The URI.InvalidURIExceptionpublic java.net.URI getURI()
public java.lang.String getHeaderValue(java.lang.String name)
name - The header name.null if none.public java.lang.String[] getHeaderValues(java.lang.String name)
name - The header name.null if none.public <any> getHeaderValueList(java.lang.String name)
name - The header name.null if none.public Header getHeader(java.lang.String name)
name - The header name.null if none.public java.lang.String getParameterValue(java.lang.String name)
name - The parameter name.null if none.public java.lang.String[] getParameterValues(java.lang.String name)
name - The parameter name.null if none.public <any> getParameterValueList(java.lang.String name)
name - The parameter name.public java.util.Collection<Header> getHeaders()
public java.util.Collection<Parameter> getParameters()
public ByteString getBody()
null if none.public java.lang.String getContentType()
Content-Type header.null if none.public java.lang.String getCharset(java.lang.String defaultCharset)
Content-Type header, if any.defaultCharset - The default charset to return if none is specified in the header.public boolean isFormEncoded()
application/x-www-form-urlencodedpublic java.lang.String getRemoteAddr()
null if unavailable.public java.lang.String getServerName()
Host header.null if unspecified.public java.util.List<java.lang.String> getPathComponents()
public static final java.util.List<java.lang.String> getPathComponents(java.lang.String uri)
throws InvalidURIException
uri - The URI.InvalidURIException - on invalid URI.public Request addHeaders(java.util.Collection<Header> headers)
headers - The headers to add.public static final byte[] bodyFromInputStream(java.io.InputStream is,
int maxBytesRead)
throws java.io.IOException
Reads the body up to the specified maximum number of bytes. If byte limit is exceeded, continues to read the rest of the stream, ignoring the data.
is - The input stream.maxBytesRead - The maximum bytes read.java.io.IOException - on input exception, or data limit exceeded.public static final java.util.Map<java.lang.String,Parameter> parseParameters(java.lang.String queryString)
Case is ignored for all names - all are converted to lower-case.
queryString - The query string.public static final java.util.Map<java.lang.String,Parameter> parseParametersPreserveNameCase(java.lang.String queryString)
queryString - The query string.public static final java.util.Map<java.lang.String,Parameter> parseParameters(java.lang.String queryString, boolean caseSensitiveNames)
Query string should already be unescaped.
queryString - The query string.caseSensitiveNames - Should case be preserved for parameter names?public java.lang.String toString()
toString in class java.lang.Object