Request.Forwarding
Constructor and Description |
---|
RequestImpl(com.google.inject.Injector injector,
NativeRequest req,
String contextPath,
int port,
Route route,
Charset charset,
Locale locale,
Map<Object,Object> scope,
Map<String,Object> locals) |
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.
|
Map<String,Object> |
attributes()
A read only version of the current locals.
|
Mutant |
body()
HTTP body.
|
Charset |
charset()
The charset defined in the request body.
|
String |
contextPath()
Application path (a.k.a context path).
|
Mutant |
cookie(String name)
Get a cookie with the given name (if present).
|
List<Cookie> |
cookies() |
void |
done() |
Mutant |
header(String name)
Get a HTTP header.
|
Map<String,Mutant> |
headers() |
String |
hostname()
The fully qualified name of the resource being requested, as obtained from the Host HTTP
header.
|
<T> Optional<T> |
ifGet(String name)
Get a request local attribute.
|
Optional<Session> |
ifSession() |
String |
ip() |
long |
length() |
Locale |
locale(Iterable<Locale> locales)
Select a locale in the provided
collection based on the content of the
Accept-Language header using the lookup algorithm of RFC4647. |
List<Locale> |
locales()
Get the content of the
Accept-Language header. |
boolean |
matches(String pattern)
Test if the given request path matches the pattern.
|
Mutant |
param(String name)
Get a HTTP request parameter under the given name.
|
Mutant |
params()
Get all the available parameters.
|
int |
port() |
String |
protocol() |
<T> T |
require(com.google.inject.Key<T> key)
Ask Guice for the given type.
|
Route |
route() |
boolean |
secure() |
Session |
session() |
Request |
set(com.google.inject.Key<?> key,
Object value)
Seed a
RequestScoped object. |
Request |
set(String name,
Object value)
Set local attribute.
|
String |
toString() |
MediaType |
type() |
<T> Optional<T> |
unset(String name)
Remove a request local attribute.
|
public String contextPath()
Request
application.path
. Default is: /
contextPath
in interface Request
public <T> Optional<T> ifGet(String name)
Request
public boolean matches(String pattern)
Request
public Map<String,Object> attributes()
Request
attributes
in interface Request
public <T> Optional<T> unset(String name)
Request
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 params()
Request
/path/:name
or /path/{name}
?name=jooby
Content-Type
is
application/x-www-form-urlencoded
or multipart/form-data
public Mutant param(String name)
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).value()); assertEquals("jooby", req.param(name).toList().get(0)); assertEquals("rocks", req.param(name).toList().get(1));Uploads can be retrieved too when
Content-Type
is multipart/form-data
see Upload
for more information.public Mutant header(String name)
Request
public Mutant cookie(String name)
Request
public <T> T require(com.google.inject.Key<T> key)
Request
public Charset charset()
Request
application.charset
.public long length()
public List<Locale> locales()
Request
Accept-Language
header. If the request doens't specify
such header, this method return the global locale: application.lang
.public Locale locale(Iterable<Locale> locales)
Request
collection
based on the content of the
Accept-Language
header using the lookup algorithm of RFC4647. If the request
doens't specify such header, this method return the global locale:
application.lang
.public String ip()
public Route route()
public String hostname()
Request
public int port()
public Session session()
public String protocol()
public boolean secure()
public Request set(String name, Object value)
Request
public Request set(com.google.inject.Key<?> key, Object value)
Request
RequestScoped
object.public void done()
Copyright © 2016. All rights reserved.