Request.Forwarding
Constructor and Description |
---|
RequestImpl(com.google.inject.Injector injector,
NativeRequest req,
String contextPath,
int port,
Route route,
Charset charset,
List<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(BiFunction<List<Locale.LanguageRange>,List<Locale>,Locale> filter)
Get a locale that best matches the current request.
|
List<Locale> |
locales(BiFunction<List<Locale.LanguageRange>,List<Locale>,List<Locale>> filter)
Get a list of locale that best matches the current request.
|
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(BiFunction<List<Locale.LanguageRange>,List<Locale>,List<Locale>> filter)
Request
Accept-Language
as
Locale.LanguageRange
and filter while the second argument is a list of supported
locales defined by the application.lang
property.
The next example returns a list of matching Locale
instances using the filtering
mechanism defined in RFC 4647:
req.locales(Locale::filter)
public Locale locale(BiFunction<List<Locale.LanguageRange>,List<Locale>,Locale> filter)
Request
Accept-Language
as
Locale.LanguageRange
and filter while the second argument is a list of supported
locales defined by the application.lang
property.
The next example returns a Locale
instance for the best-matching language
tag using the lookup mechanism defined in RFC 4647.
req.locale(Locale::lookup)
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.