Package org.attribyte.api.http
Class Request
java.lang.Object
org.attribyte.api.http.Request
An immutable HTTP request.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionAn immutable map of attributes.final com.google.protobuf.ByteStringThe request body.final booleanIf the request has parameters, are they case-sensitive?final com.google.common.collect.ImmutableList<Cookie> An immutable list of cookies.static final StringThe expected value for a form encoded header:application/x-www-form-urlencoded.An immutable map of headers.final Request.MethodThe request method.An immutable map of parameters.static final StringThe name of an attribute that may hold the remote address.final URIThe request URI. -
Method Summary
Modifier and TypeMethodDescriptionaddHeaders(Collection<Header> headers) Adds headers to the existing headers, replacing any that are duplicated.static final byte[]bodyFromInputStream(InputStream is, int maxBytesRead) Reads the request body from an input stream.com.google.protobuf.ByteStringgetBody()Gets the request body, if any.getCharset(String defaultCharset) Gets the charset specified with the requestContent-Typeheader, if any.Gets the value of theContent-Typeheader.Gets a header.Gets all headers.getHeaderValue(String name) Gets the first header value.com.google.common.collect.ImmutableList<String> getHeaderValueList(String name) Gets an immutable list of values for a header.String[]getHeaderValues(String name) Gets all values for a header.static final StringgetHostURL(String uri) Gets a URL for the host portion of a URI without decoding.Gets the HTTP method.Gets all parameters.getParameterValue(String name) Gets the first parameter value.com.google.common.collect.ImmutableList<String> getParameterValueList(String name) Gets an immutable list of values for a parameter.String[]getParameterValues(String name) Gets all values for a parameter.Gets the components of the path (separated by '/').getPathComponents(String uri) Gets the components of the path (separated by '/').Gets the decoded query string.Gets the raw query string, without decoding.Gets the IP address of the client that sent the request.Gets the path component of the request URI.static final StringgetRequestPath(String uri) Gets the path component of a URI.Gets the server name (as specified in theHostheader.getURI()Gets the URI.booleanDetermine if the request is encoded as a formapplication/x-www-form-urlencodedparseParameters(String queryString) Parse parameters from a query string.parseParameters(String queryString, boolean caseSensitiveNames) Parse parameters from a query string.parseParametersPreserveNameCase(String queryString) Parse parameters from a query string, preserving case in parameter names.toString()
-
Field Details
-
FORM_ENCODED_CONTENT_TYPE
The expected value for a form encoded header:application/x-www-form-urlencoded.- See Also:
-
REMOTE_ADDR
The name of an attribute that may hold the remote address.- See Also:
-
method
The request method. -
uri
The request URI. -
headers
An immutable map of headers.Keys are lower-cased.
-
parameters
An immutable map of parameters.If
caseSensitiveParameters == false, map keys are lower-cased. -
attributes
An immutable map of attributes. -
cookies
An immutable list of cookies. -
body
public final com.google.protobuf.ByteString bodyThe request body. May be null. -
caseSensitiveParameters
public final boolean caseSensitiveParametersIf the request has parameters, are they case-sensitive?
-
-
Method Details
-
getMethod
Gets the HTTP method.- Returns:
- The method.
-
getQueryString
Gets the decoded query string.- Returns:
- The decoded query string or
nullif none.
-
getRawQueryString
Gets the raw query string, without decoding.- Returns:
- The query string or
nullif none.
-
getRequestPath
Gets the path component of the request URI.Path always begins with '/' and is never
null.- Returns:
- The path.
-
getRequestPath
Gets the path component of a URI.Path always begins with '/' and is never
null. Components are decoded.- Parameters:
uri- The URI.- Returns:
- The path.
- Throws:
org.attribyte.api.InvalidURIException- if URI is invalid.
-
getHostURL
Gets a URL for the host portion of a URI without decoding.Includes the protocol, if specified. Never ends with '/'.
- Parameters:
uri- The URI.- Returns:
- The host URL.
- Throws:
org.attribyte.api.InvalidURIException- if the URI can't be parsed.
-
getURI
Gets the URI.- Returns:
- The URI.
-
getHeaderValue
Gets the first header value.- Parameters:
name- The header name.- Returns:
- The value or
nullif none.
-
getHeaderValues
Gets all values for a header.- Parameters:
name- The header name.- Returns:
- The values or
nullif none.
-
getHeaderValueList
Gets an immutable list of values for a header.- Parameters:
name- The header name.- Returns:
- The values or
nullif none.
-
getHeader
Gets a header.- Parameters:
name- The header name.- Returns:
- The header or
nullif none.
-
getParameterValue
Gets the first parameter value.- Parameters:
name- The parameter name.- Returns:
- The value or
nullif none.
-
getParameterValues
Gets all values for a parameter.- Parameters:
name- The parameter name.- Returns:
- The values or
nullif none.
-
getParameterValueList
Gets an immutable list of values for a parameter.- Parameters:
name- The parameter name.- Returns:
- The immutable list of values.
-
getHeaders
Gets all headers.- Returns:
- An unmodifiable collection of headers.
-
getParameters
Gets all parameters.- Returns:
- An unmodifiable collection of parameters.
-
getBody
public com.google.protobuf.ByteString getBody()Gets the request body, if any.- Returns:
- The body, or
nullif none.
-
getContentType
Gets the value of theContent-Typeheader.- Returns:
- The content type, or
nullif none.
-
getCharset
Gets the charset specified with the requestContent-Typeheader, if any.- Parameters:
defaultCharset- The default charset to return if none is specified in the header.- Returns:
- The charset or the default charset.
-
isFormEncoded
public boolean isFormEncoded()Determine if the request is encoded as a formapplication/x-www-form-urlencoded- Returns:
- Is the request encoded as a form?
-
getRemoteAddr
Gets the IP address of the client that sent the request.- Returns:
- The IP address or
nullif unavailable.
-
getServerName
Gets the server name (as specified in theHostheader.- Returns:
- The server name, excluding any port, or
nullif unspecified.
-
getPathComponents
Gets the components of the path (separated by '/').- Returns:
- The path components, or empty list if none.
-
getPathComponents
public static final List<String> getPathComponents(String uri) throws org.attribyte.api.InvalidURIException Gets the components of the path (separated by '/').- Parameters:
uri- The URI.- Returns:
- The path components, or empty list if none.
- Throws:
org.attribyte.api.InvalidURIException- on invalid URI.
-
addHeaders
Adds headers to the existing headers, replacing any that are duplicated.- Parameters:
headers- The headers to add.- Returns:
- The request with additional headers added.
-
bodyFromInputStream
Reads the request body from an input stream.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.
- Parameters:
is- The input stream.maxBytesRead- The maximum bytes read.- Returns:
- The body.
- Throws:
IOException- on input exception, or data limit exceeded.
-
parseParameters
Parse parameters from a query string.Case is ignored for all names - all are converted to lower-case.
- Parameters:
queryString- The query string.- Returns:
- The map of parameters.
-
parseParametersPreserveNameCase
Parse parameters from a query string, preserving case in parameter names.- Parameters:
queryString- The query string.- Returns:
- The map of parameters.
-
parseParameters
public static final Map<String,Parameter> parseParameters(String queryString, boolean caseSensitiveNames) Parse parameters from a query string.Query string should already be unescaped.
- Parameters:
queryString- The query string.caseSensitiveNames- Should case be preserved for parameter names?- Returns:
- The map of parameters.
-
toString
-