public abstract class HttpRequest extends HttpMessage
An HTTP request message.
Modifier and Type | Class and Description |
---|---|
static class |
HttpRequest.Builder |
Modifier and Type | Field and Description |
---|---|
static String |
RFC1123_DATE
The only date format permitted when generating HTTP headers.
|
Constructor and Description |
---|
HttpRequest() |
Modifier and Type | Method and Description |
---|---|
protected String |
contentString() |
Object |
getAttribute(String name)
Returns the value of the given attribute.
|
abstract Map<String,Object> |
getAttributes()
Returns the names values of all attributed associated with this request.
|
abstract String |
getContextPath()
The portion of the request URI that indicates the context of the request.
|
long |
getDateHeader(String name)
Returns the value of the specified request header as a
long value that represents a Date object. |
abstract ActorRef<WebMessage> |
getFrom()
Returns an actor representing the client to which an
HttpResponse should be sent as a response to this request. |
abstract String |
getMethod()
The name of the HTTP method with which this request was made; for example, GET, POST, or PUT.
|
String |
getParameter(String name)
Returns the value of the given parameter.
|
abstract Multimap<String,String> |
getParameters()
A multimap of the parameters contained in this message and (all) their values.
|
Collection<String> |
getParametersValues(String name)
Returns all values associated with the given parameter
|
abstract String |
getPathInfo()
Returns any extra path information associated with the URL the client sent when it made this request.
|
abstract String |
getQueryString()
The query string that is contained in the request URL after the path, or
null if the URL does not have a query string. |
abstract String |
getRequestURI()
Returns the part of this request’s URL from the protocol name up to the query string in the first line of the HTTP request.
|
String |
getRequestURL()
Reconstructs the URL the client used to make the request.
|
abstract String |
getScheme()
Returns the name of the scheme used to make this request, for example,
http , https , or ftp . |
abstract String |
getServerName()
The host name of the server to which the request was sent.
|
abstract int |
getServerPort()
The port number to which the request was sent.
|
abstract String |
getSourceHost()
The Internet Protocol (IP) host that sent the request or
null if not available. |
abstract int |
getSourcePort()
The Internet Protocol (IP) port from which the request was sent or
-1 if not available. |
getCharacterEncoding, getContentLength, getContentType, getCookies, getHeader, getHeaders, getHeaderValues
getByteBufferBody, getStringBody
toString
public static final String RFC1123_DATE
The only date format permitted when generating HTTP headers.
public abstract String getSourceHost()
The Internet Protocol (IP) host that sent the request or null
if not available.
public abstract int getSourcePort()
The Internet Protocol (IP) port from which the request was sent or -1
if not available.
public abstract Multimap<String,String> getParameters()
A multimap of the parameters contained in this message and (all) their values. If the request has no parameters, returns an empty multimap.
public abstract Map<String,Object> getAttributes()
Returns the names values of all attributed associated with this request.
The container may set attributes to make available custom information about a request. For example, for requests made using HTTPS, the attribute javax.servlet.request.X509Certificate
can be used to retrieve information on the certificate of the client.
Object
containing the value of the attribute, or null
if the attribute does not existpublic Collection<String> getParametersValues(String name)
Returns all values associated with the given parameter
name
- the parameter namepublic String getParameter(String name)
Returns the value of the given parameter. If the parameter is not found in the message, this method returns null
. If the parameter has more than one value, this method returns the first value.
name
- the parameter namenull
if the parameter is not foundpublic Object getAttribute(String name)
Returns the value of the given attribute. If the attribute is not found in the message, this method returns null
.
name
- the attribute namenull
if the attribute is not foundpublic abstract String getScheme()
Returns the name of the scheme used to make this request, for example, http
, https
, or ftp
. Different schemes have different rules for constructing URLs, as noted in RFC 1738.
public abstract String getMethod()
The name of the HTTP method with which this request was made; for example, GET, POST, or PUT.
public long getDateHeader(String name)
Returns the value of the specified request header as a long
value that represents a Date
object. Use this method with headers that contain dates, such as If-Modified-Since
.
The date is returned as the number of milliseconds since January 1, 1970 GMT.
If the request does not have a header of the specified name, this method returns -1. If the header can’t be converted to a date, the method throws an IllegalArgumentException
.
name
- the name of the headerlong
value representing the date specified in the header expressed as the number of milliseconds since January 1, 1970 GMT, or -1
if the named header was not included with the requestIllegalArgumentException
- If the header value can’t be converted to a datepublic abstract String getPathInfo()
Returns any extra path information associated with the URL the client sent when it made this request. The extra path information follows the servlet path but precedes the query string and will start with a “/” character.
This method returns null
if there was no extra path information.
String
decoded by the web container, specifying extra path information that comes after the servlet path but before the query string in the request URL; or null
if the URL does not have any extra path informationpublic abstract String getContextPath()
The portion of the request URI that indicates the context of the request. The context path always comes first in a request URI. The path starts with a “/” character but does not end with a “/” character. For servlets in the default (root) context, this method returns "". The container does not decode this string.
It is possible that a container may match a context by more than one context path. In such cases this method will return the actual context path used by the request.
public abstract String getQueryString()
The query string that is contained in the request URL after the path, or null
if the URL does not have a query string.
public abstract String getRequestURI()
Returns the part of this request’s URL from the protocol name up to the query string in the first line of the HTTP request. The web container does not decode this string. For example:
First line of HTTP request | Returned Value | |
---|---|---|
POST /some/path.html HTTP/1.1 | /some/path.html | |
GET http://foo.bar/a.html HTTP/1.0 | /a.html | |
HEAD /xyz?a=b HTTP/1.1 | /xyz |
public String getRequestURL()
Reconstructs the URL the client used to make the request. The returned URL contains a protocol, server name, port number, and server path, but it does not include query string parameters.
This method is useful for creating redirect messages and for reporting errors.
public abstract String getServerName()
The host name of the server to which the request was sent. It is the value of the part before “:” in the Host
header value, if any, or the resolved server name, or the server IP address.
public abstract int getServerPort()
The port number to which the request was sent. It is the value of the part after “:” in the Host
header value, if any, or the server port where the client connection was accepted on.
public abstract ActorRef<WebMessage> getFrom()
Returns an actor representing the client to which an HttpResponse
should be sent as a response to this request. All HttpRequest
s from the same session will have the same sender. It will appear to have died (i.e. send an ExitMessage
if watched
) when the session is terminated.
getFrom
in interface FromMessage
getFrom
in class WebMessage
protected String contentString()
contentString
in class WebMessage