public class HttpRequest extends Object
Modifier and Type | Field and Description |
---|---|
protected static int |
AFTER
after filter code.
|
protected static int |
AFTER_ALL
after all filter code.
|
protected static int |
BEFORE
before filter code.
|
protected static int |
BEFORE_ALL
before all filter code.
|
static int |
CONNECT
Value returned by
getMethod() if the request method is CONNECT . |
static int |
DELETE
Value returned by
getMethod() if the request method is DELETE . |
static int |
GET
Value returned by
getMethod() if the request method is GET . |
static int |
HEAD
Value returned by
getMethod() if the request method is HEAD . |
static int |
OPTIONS
Value returned by
getMethod() if the request method is OPTIONS . |
static int |
PATCH
Value returned by
getMethod() if the request method is PATCH . |
static int |
POST
Value returned by
getMethod() if the request method is POST . |
static int |
PUT
Value returned by
getMethod() if the request method is PUT . |
static int |
TRACE
Value returned by
getMethod() if the request method is TRACE . |
Modifier | Constructor and Description |
---|---|
protected |
HttpRequest(InputStream inputStream,
EncodingRegistry encodingRegistry)
Constructs a new instance of HTTPRequest.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addPathParameters(Map<String,String> parameters)
Adds path parameters from a given list to the list of path path parameters of the request.
|
protected void |
addSplatParameters(List<String> splatParameters)
Sets the splat Parameters.
|
Object |
getAttribute(String key)
Get request server-side attribute by key.
|
String |
getCookie(String name)
Return the cookie of the request with given name.
|
Map<String,String> |
getCookies()
Returns the cookies of the request.
|
String |
getHeader(String name)
Returns the header field value associated to the given header field
name . |
Map<String,String> |
getHeaders()
Returns all HTTP header fields of the request.
|
int |
getMethod()
|
String |
getPathParam(String param)
Returns the path parameter value mapped to the given name.
|
String |
getQueryParam(String name)
Returns the query parameter mapped to the given name.
|
Map<String,String> |
getQueryParams()
Returns the Query parameters as
Map . |
InputStream |
getRequestBody()
use
parseBody(BodyParser) for more option on request body provided parsers. |
List<String> |
getSplatParams()
Returns the list of splat parameters.
|
String |
getURI()
Returns the request URI.
|
String |
getVersion()
Returns the HTTP version request.
|
<T> T |
parseBody(BodyParser<T> bodyParser)
Request the body to be parsed.
|
void |
setAttribute(String key,
Object value)
Set a request server-side attribute.
|
protected static final int AFTER
protected static final int AFTER_ALL
protected static final int BEFORE
protected static final int BEFORE_ALL
public static final int CONNECT
getMethod()
if the request method is CONNECT
.public static final int DELETE
getMethod()
if the request method is DELETE
.public static final int GET
getMethod()
if the request method is GET
.public static final int HEAD
getMethod()
if the request method is HEAD
.public static final int OPTIONS
getMethod()
if the request method is OPTIONS
.public static final int PATCH
getMethod()
if the request method is PATCH
.public static final int POST
getMethod()
if the request method is POST
.public static final int PUT
getMethod()
if the request method is PUT
.public static final int TRACE
getMethod()
if the request method is TRACE
.protected HttpRequest(InputStream inputStream, EncodingRegistry encodingRegistry) throws IOException
inputStream
- the input stream of the request.encodingRegistry
- the register of available encoding and transfer coding handlers.IOException
- if connection is lost during processing the request.IllegalArgumentException
- if parsing the request failed.protected void addPathParameters(Map<String,String> parameters)
parameters
- path parameters to be added to the requestprotected void addSplatParameters(List<String> splatParameters)
splatParameters
- the splat parameters to set.@Nullable public Object getAttribute(String key)
key
- attribute key@Nullable public String getCookie(@Nullable String name)
Cookies are lazily parsed.
name
- the name of the cookie.null
if name
is null
.public Map<String,String> getCookies()
Cookies are lazily parsed.
Map
of (String,String) representing the HTTP cookies (may be empty)@Nullable public String getHeader(@Nullable String name)
name
.name
- the header field name.null
if the header field is not found or name
is null.public Map<String,String> getHeaders()
Map
of (String,String) representing the HTTP header fields (may be empty).@Nullable public String getPathParam(String param)
param
- path parameter name@Nullable public String getQueryParam(String name)
name
- of query parameterpublic Map<String,String> getQueryParams()
Map
.Map
of (String,String) representing the HTTP query parameters.public InputStream getRequestBody()
parseBody(BodyParser)
for more option on request body provided parsers.public List<String> getSplatParams()
List
of splat parameters.public String getURI()
public String getVersion()
public <T> T parseBody(BodyParser<T> bodyParser) throws IOException
T
- the type of body.bodyParser
- the parser.IOException
- if an IOException
occurs during parsing.