public interface Request
Modifier and Type | Interface and Description |
---|---|
static class |
Request.Forwarding
Forwarding request.
|
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.
|
default Optional<MediaType> |
accepts(MediaType... types)
Check if the given types are acceptable, returning the best match when true, or else
Optional.empty.
|
default Optional<MediaType> |
accepts(String... 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.
|
Optional<Cookie> |
cookie(String name)
Get a cookie with the given name (if present).
|
List<Cookie> |
cookies() |
<T> Optional<T> |
get(String name)
Get a request local attribute.
|
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() |
default boolean |
isSet(String name) |
long |
length() |
Locale |
locale()
Get the content of the
Accept-Language header. |
default String |
method() |
Mutant |
param(String name)
Get a HTTP request parameter under the given name.
|
Mutant |
params()
Get all the available parameters.
|
default String |
path()
Given:
|
int |
port() |
String |
protocol() |
default <T> T |
require(Class<T> type)
Ask Guice for the given type.
|
<T> T |
require(com.google.inject.Key<T> key)
Ask Guice for the given type.
|
default <T> T |
require(String name,
Class<T> type)
Ask Guice for the given type.
|
default <T> T |
require(com.google.inject.TypeLiteral<T> type)
Ask Guice for the given type.
|
Route |
route() |
boolean |
secure() |
Session |
session() |
default Request |
set(Class<?> type,
Object value)
Seed a
RequestScoped object. |
Request |
set(com.google.inject.Key<?> key,
Object value)
Seed a
RequestScoped object. |
Request |
set(String name,
Object value)
Set local attribute.
|
default Request |
set(com.google.inject.TypeLiteral<?> type,
Object value)
Seed a
RequestScoped object. |
MediaType |
type() |
<T> Optional<T> |
unset(String name)
Remove a request local attribute.
|
default boolean |
xhr() |
default String path()
http://domain.com/some/path.html -> /some/path.html http://domain.com/a.html -> /a.html
default String method()
MediaType type()
Content-Type
header. Default is: /.default Optional<MediaType> accepts(String... types)
// 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"
types
- Types to test.default Optional<MediaType> accepts(MediaType... types)
// 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"
types
- Types to test.Optional<MediaType> accepts(List<MediaType> types)
// 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"
types
- Types to test for.Mutant params()
/path/:name
or /path/{name}
?name=jooby
Content-Type
is
application/x-www-form-urlencoded
or multipart/form-data
Mutant param(String name)
/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(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.name
- A parameter's name.Mutant header(String name)
name
- A header's name.Optional<Cookie> cookie(String name)
name
- Cookie's name.Mutant body() throws Exception
Exception
- If body can't be converted or there is no HTTP body.default <T> T require(Class<T> type)
T
- Service type.type
- A service type.default <T> T require(String name, Class<T> type)
T
- Service type.name
- A service name.type
- A service type.default <T> T require(com.google.inject.TypeLiteral<T> type)
T
- Service type.type
- A service type.<T> T require(com.google.inject.Key<T> key)
T
- Service type.key
- A service key.Charset charset()
application.charset
.Locale locale()
Accept-Language
header. If the request doens't specify
such header, this method return the global locale: application.lang
.long length()
-1
if the length is not known.String ip()
int port()
host
header or the server port where the client
connection was accepted on.String hostname()
Session session()
Optional<Session> ifSession()
default boolean xhr()
X-Requested-With
header is set to XMLHttpRequest
.String protocol()
boolean secure()
Request set(String name, Object value)
name
- Attribute's name.value
- Attribute's local. NOT null.default boolean isSet(String name)
name
- Attribute's name.<T> Optional<T> get(String name)
T
- Target type.name
- Attribute's name.<T> Optional<T> unset(String name)
T
- Target type.name
- Attribute's name.Map<String,Object> attributes()
default Request set(Class<?> type, Object value)
RequestScoped
object.type
- Object type.value
- Actual object to bind.default Request set(com.google.inject.TypeLiteral<?> type, Object value)
RequestScoped
object.type
- Seed type.value
- Actual object to bind.Request set(com.google.inject.Key<?> key, Object value)
RequestScoped
object.key
- Seed key.value
- Actual object to bind.Copyright © 2015. All rights reserved.