Request.Forwarding, Request.Module
Constructor and Description |
---|
RequestImpl(javax.servlet.http.HttpServletRequest request,
com.google.inject.Injector injector,
Route route,
BodyConverterSelector selector,
MediaType contentType,
List<MediaType> accept,
Charset charset,
Locale locale) |
Modifier and Type | Method and Description |
---|---|
List<MediaType> |
accept() |
Optional<MediaType> |
accepts(List<MediaType> types)
Check if the given types are acceptable, returning the best match when true, or else
Optional.empty.
|
<T> T |
body(com.google.inject.TypeLiteral<T> type)
Convert the HTTP request body into the given type.
|
Charset |
charset()
The charset defined in the request body.
|
Optional<Cookie> |
cookie(String name)
Get a cookie with the given name (if present).
|
List<Cookie> |
cookies() |
void |
destroy() |
<T> T |
getInstance(com.google.inject.Key<T> key)
Ask Guice for the given type.
|
Mutant |
header(String name)
Get a HTTP header.
|
Map<String,Mutant> |
headers() |
String |
hostname()
The fully qualified name of the client or the last proxy that sent the request.
|
Optional<Session> |
ifSession() |
String |
ip() |
long |
length() |
Locale |
locale()
Get the content of the
Accept-Language header. |
Mutant |
param(String name)
Get a HTTP request parameter under the given name.
|
Map<String,Mutant> |
params()
Get all the available parameter.
|
String |
path()
Given:
|
String |
protocol() |
protected List<String> |
reqParams(String name) |
protected List<Upload> |
reqUploads(String name) |
Route |
route() |
boolean |
secure() |
Session |
session() |
String |
toString() |
MediaType |
type() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
accepts, accepts, body, getInstance, getInstance, verb, xhr
public String path()
Request
http://domain.com/some/path.html -> /some/path.html http://domain.com/a.html -> /a.html
public MediaType type()
public Optional<MediaType> accepts(List<MediaType> types)
Request
// Accept: text/html req.accepts("text/html"); // => "text/html" // Accept: text/*, application/json req.accepts("text/html"); // => "text/html" req.accepts("text/html"); // => "text/html" req.accepts("application/json" "text/plain"); // => "application/json" req.accepts("application/json"); // => "application/json" // Accept: text/*, application/json req.accepts("image/png"); // => Optional.empty // Accept: text/*;q=.5, application/json req.accepts("text/html", "application/json"); // => "application/json"
public Mutant param(String name) throws Exception
Request
/path/:name
or /path/{name}
?name=jooby
Content-Type
is
application/x-www-form-urlencoded
or multipart/form-data
path
, query
and body
. For
example a pattern like: GET /path/:name
for /path/jooby?name=rocks
produces:
assertEquals("jooby", req.param(name).stringValue()); assertEquals("jooby", req.param(name).toList(String.class).get(0)); assertEquals("rocks", req.param(name).toList(String.class).get(1));Uploads can be retrieved too when
Content-Type
is multipart/form-data
see Upload
for more information.public Map<String,Mutant> params() throws Exception
Request
/path/:name
or /path/{name}
?name=jooby
Content-Type
is
application/x-www-form-urlencoded
or multipart/form-data
public String ip()
public String hostname()
Request
public String protocol()
public boolean secure()
public Session session()
public Mutant header(String name)
Request
public <T> T body(com.google.inject.TypeLiteral<T> type) throws Exception
Request
public Optional<Cookie> cookie(String name)
Request
public <T> T getInstance(com.google.inject.Key<T> key)
Request
getInstance
in interface Request
T
- Service type.key
- A service key.Request.Module
public void destroy()
public Charset charset()
Request
application.charset
.public long length()
public Locale locale()
Request
Accept-Language
header. If the request doens't specify
such header, this method return the global locale: application.lang
.public Route route()
Copyright © 2014. All rights reserved.