Package play.mvc
Class Http.RequestBuilder
- Object
-
- play.mvc.Http.RequestBuilder
-
-
Field Summary
Fields Modifier and Type Field Description protected play.api.mvc.Request<Http.RequestBody>
req
-
Constructor Summary
Constructors Constructor Description RequestBuilder()
Returns a simple request builder.RequestBuilder(play.api.mvc.request.RequestFactory requestFactory)
Returns a simple request builder.RequestBuilder(Http.RequestBuilder copy)
Returns a request builder as copy of the passed request builder.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description <T> Http.RequestBuilder
attr(TypedKey<T> key, T value)
Add an attribute to the request.TypedMap
attrs()
Http.RequestBuilder
attrs(TypedMap newAttrs)
Update the request attributes.Http.RequestBody
body()
protected Http.RequestBuilder
body(Http.RequestBody body)
Set the body of the request.protected Http.RequestBuilder
body(Http.RequestBody body, String contentType)
Set the body of the request.Http.RequestBuilder
bodyForm(Map<String,String> data)
Set a Form url encoded body to this request.Http.RequestBuilder
bodyFormArrayValues(Map<String,String[]> data)
Set a Form url encoded body to this request.Http.RequestBuilder
bodyJson(com.fasterxml.jackson.databind.JsonNode node)
Set a Json Body to this request.Http.RequestBuilder
bodyJson(play.api.libs.json.JsValue json)
Set a Json Body to this request.Http.RequestBuilder
bodyMultipart(List<Http.MultipartFormData.Part<Source<ByteString,?>>> data, Files.TemporaryFileCreator temporaryFileCreator, Materializer mat)
Deprecated.Deprecated as of 2.7.0.Http.RequestBuilder
bodyMultipart(Map<String,String[]> formData, List<Http.MultipartFormData.FilePart> files)
Set a Multipart Form url encoded body to this request.Http.RequestBuilder
bodyRaw(byte[] data)
Set a Binary Data to this request using a singleton temporary file creator.Http.RequestBuilder
bodyRaw(byte[] data, Files.TemporaryFileCreator tempFileCreator)
Set a Binary Data to this request.Http.RequestBuilder
bodyRaw(ByteString data)
Set a Binary Data to this request using a singleton temp file creator TheContent-Type
header of the request is set toapplication/octet-stream
.Http.RequestBuilder
bodyRaw(ByteString data, Files.TemporaryFileCreator tempFileCreator)
Set a Binary Data to this request.Http.RequestBuilder
bodyRaw(List<Http.MultipartFormData.Part<Source<ByteString,?>>> data, Files.TemporaryFileCreator temporaryFileCreator, Materializer mat)
Set a Multipart Form url encoded body to this request saving it as a raw body.Http.RequestBuilder
bodyText(String text)
Set a Text to this request.Http.RequestBuilder
bodyText(String text, Charset charset)
Set a Text to this request.Http.RequestBuilder
bodyXml(Document xml)
Set a XML to this request.Http.RequestBuilder
bodyXml(InputSource xml)
Set a XML to this request.Http.RequestImpl
build()
Builds the request.Optional<List<X509Certificate>>
clientCertificateChain()
Http.RequestBuilder
clientCertificateChain(List<X509Certificate> clientCertificateChain)
Http.RequestBuilder
cookie(Http.Cookie cookie)
Sets one cookie.Http.Cookies
cookies()
Map<String,String>
flash()
Http.RequestBuilder
flash(String key, String value)
Sets a cookie in the request.Http.RequestBuilder
flash(Map<String,String> data)
Sets cookies in a request.Http.Headers
getHeaders()
Deprecated.Deprecated as of 2.9.0.Http.RequestBuilder
header(String key, String value)
Http.RequestBuilder
header(String key, List<String> values)
Http.Headers
headers()
Http.RequestBuilder
headers(Http.Headers headers)
Set the headers to be used by the request builder.String
host()
Http.RequestBuilder
host(String host)
Long
id()
Http.RequestBuilder
id(Long id)
Http.RequestBuilder
langCookie(Locale locale, MessagesApi messagesApi)
Sets given lang in a cookie.Http.RequestBuilder
langCookie(Lang lang, MessagesApi messagesApi)
Sets given lang in a cookie.String
method()
Http.RequestBuilder
method(String method)
String
path()
Http.RequestBuilder
path(String path)
This method sets the path of the uri.String
remoteAddress()
Http.RequestBuilder
remoteAddress(String remoteAddress)
boolean
secure()
Http.RequestBuilder
secure(boolean secure)
Map<String,String>
session()
Http.RequestBuilder
session(String key, String value)
Sets a session.Http.RequestBuilder
session(Map<String,String> data)
Sets all parameters for the session.Http.RequestBuilder
transientLang(String code)
Deprecated.Deprecated as of 2.8.0 UsetransientLang(Lang)
instead.Http.RequestBuilder
transientLang(Locale locale)
Sets the transient language.Http.RequestBuilder
transientLang(Lang lang)
Sets the transient language.String
uri()
Http.RequestBuilder
uri(String str)
Sets the uri.Http.RequestBuilder
uri(URI uri)
String
version()
Http.RequestBuilder
version(String version)
Http.RequestBuilder
withoutTransientLang()
Removes the transient language.
-
-
-
Field Detail
-
req
protected play.api.mvc.Request<Http.RequestBody> req
-
-
Constructor Detail
-
RequestBuilder
public RequestBuilder()
Returns a simple request builder. The initial request is "GET / HTTP/1.1" from 127.0.0.1 over an insecure connection. The request is created using the default factory.
-
RequestBuilder
public RequestBuilder(Http.RequestBuilder copy)
Returns a request builder as copy of the passed request builder.
-
RequestBuilder
public RequestBuilder(play.api.mvc.request.RequestFactory requestFactory)
Returns a simple request builder. The initial request is "GET / HTTP/1.1" from 127.0.0.1 over an insecure connection. The request is created using the given factory.- Parameters:
requestFactory
- the incoming request factory
-
-
Method Detail
-
body
public Http.RequestBody body()
- Returns:
- the request body, if a previously the body has been set
-
body
protected Http.RequestBuilder body(Http.RequestBody body, String contentType)
Set the body of the request.- Parameters:
body
- the bodycontentType
- Content-Type header value- Returns:
- the modified builder
-
body
protected Http.RequestBuilder body(Http.RequestBody body)
Set the body of the request.- Parameters:
body
- The body.- Returns:
- the modified builder
-
bodyRaw
public Http.RequestBuilder bodyRaw(ByteString data)
Set a Binary Data to this request using a singleton temp file creator TheContent-Type
header of the request is set toapplication/octet-stream
.- Parameters:
data
- the Binary Data- Returns:
- the modified builder
-
bodyRaw
public Http.RequestBuilder bodyRaw(ByteString data, Files.TemporaryFileCreator tempFileCreator)
Set a Binary Data to this request. TheContent-Type
header of the request is set toapplication/octet-stream
.- Parameters:
data
- the Binary DatatempFileCreator
- the temporary file creator for binary data.- Returns:
- the modified builder
-
bodyRaw
public Http.RequestBuilder bodyRaw(byte[] data)
Set a Binary Data to this request using a singleton temporary file creator. TheContent-Type
header of the request is set toapplication/octet-stream
.- Parameters:
data
- the Binary Data- Returns:
- the modified builder
-
bodyRaw
public Http.RequestBuilder bodyRaw(byte[] data, Files.TemporaryFileCreator tempFileCreator)
Set a Binary Data to this request. TheContent-Type
header of the request is set toapplication/octet-stream
.- Parameters:
data
- the Binary DatatempFileCreator
- the temporary file creator for binary data.- Returns:
- the modified builder
-
bodyFormArrayValues
public Http.RequestBuilder bodyFormArrayValues(Map<String,String[]> data)
Set a Form url encoded body to this request.- Parameters:
data
- the x-www-form-urlencoded parameters- Returns:
- the modified builder
-
bodyForm
public Http.RequestBuilder bodyForm(Map<String,String> data)
Set a Form url encoded body to this request.- Parameters:
data
- the x-www-form-urlencoded parameters- Returns:
- the modified builder
-
bodyMultipart
@Deprecated public Http.RequestBuilder bodyMultipart(List<Http.MultipartFormData.Part<Source<ByteString,?>>> data, Files.TemporaryFileCreator temporaryFileCreator, Materializer mat)
Deprecated.Deprecated as of 2.7.0. Renamed tobodyRaw(List, Files.TemporaryFileCreator, Materializer)
.Set a Multipart Form url encoded body to this request saving it as a raw body.- Parameters:
data
- the multipart-form parameterstemporaryFileCreator
- the temporary file creator.mat
- a Akka Streams Materializer- Returns:
- the modified builder
-
bodyRaw
public Http.RequestBuilder bodyRaw(List<Http.MultipartFormData.Part<Source<ByteString,?>>> data, Files.TemporaryFileCreator temporaryFileCreator, Materializer mat)
Set a Multipart Form url encoded body to this request saving it as a raw body.- Parameters:
data
- the multipart-form parameterstemporaryFileCreator
- the temporary file creator.mat
- a Akka Streams Materializer- Returns:
- the modified builder
-
bodyMultipart
public Http.RequestBuilder bodyMultipart(Map<String,String[]> formData, List<Http.MultipartFormData.FilePart> files)
Set a Multipart Form url encoded body to this request.- Parameters:
formData
- the URL form-encoded data partfiles
- the files part- Returns:
- the modified builder
-
bodyJson
public Http.RequestBuilder bodyJson(com.fasterxml.jackson.databind.JsonNode node)
Set a Json Body to this request. TheContent-Type
header of the request is set toapplication/json
.- Parameters:
node
- the Json Node- Returns:
- this builder, updated
-
bodyJson
public Http.RequestBuilder bodyJson(play.api.libs.json.JsValue json)
Set a Json Body to this request. TheContent-Type
header of the request is set toapplication/json
.- Parameters:
json
- the JsValue- Returns:
- the modified builder
-
bodyXml
public Http.RequestBuilder bodyXml(InputSource xml)
Set a XML to this request. TheContent-Type
header of the request is set toapplication/xml
.- Parameters:
xml
- the XML- Returns:
- the modified builder
-
bodyXml
public Http.RequestBuilder bodyXml(Document xml)
Set a XML to this request.The
Content-Type
header of the request is set toapplication/xml
.- Parameters:
xml
- the XML- Returns:
- the modified builder
-
bodyText
public Http.RequestBuilder bodyText(String text)
Set a Text to this request. TheContent-Type
header of the request is set totext/plain
.- Parameters:
text
- the text, assumed to be encoded in US_ASCII format, per https://tools.ietf.org/html/rfc6657#section-4- Returns:
- this builder, updated
-
bodyText
public Http.RequestBuilder bodyText(String text, Charset charset)
Set a Text to this request. TheContent-Type
header of the request is set totext/plain; charset=$charset
.- Parameters:
text
- the text, which is assumed to be already encoded in the format defined by charset.charset
- the character set that the request is encoded in.- Returns:
- this builder, updated
-
build
public Http.RequestImpl build()
Builds the request.- Returns:
- a build of the given parameters
-
id
public Long id()
- Returns:
- the id of the request
-
id
public Http.RequestBuilder id(Long id)
- Parameters:
id
- the id to be used- Returns:
- the builder instance
-
attr
public <T> Http.RequestBuilder attr(TypedKey<T> key, T value)
Add an attribute to the request.- Type Parameters:
T
- The type of the attribute to add.- Parameters:
key
- The key of the attribute to add.value
- The value of the attribute to add.- Returns:
- the request builder with extra attribute
-
attrs
public Http.RequestBuilder attrs(TypedMap newAttrs)
Update the request attributes. This replaces all existing attributes.- Parameters:
newAttrs
- The attribute entries to add.- Returns:
- the request builder with extra attributes set.
-
attrs
public TypedMap attrs()
- Returns:
- the request builder's request attributes.
-
method
public String method()
- Returns:
- the builder instance.
-
method
public Http.RequestBuilder method(String method)
- Parameters:
method
- sets the method- Returns:
- the builder instance
-
uri
public String uri()
- Returns:
- gives the uri of the request
-
uri
public Http.RequestBuilder uri(URI uri)
-
uri
public Http.RequestBuilder uri(String str)
Sets the uri.- Parameters:
str
- the uri- Returns:
- the builder instance
-
secure
public Http.RequestBuilder secure(boolean secure)
- Parameters:
secure
- true if the request is secure- Returns:
- the builder instance
-
secure
public boolean secure()
- Returns:
- the status if the request is secure
-
host
public String host()
- Returns:
- the host name from the header
-
host
public Http.RequestBuilder host(String host)
- Parameters:
host
- sets the host in the header- Returns:
- the builder instance
-
path
public String path()
- Returns:
- the raw path of the uri
-
path
public Http.RequestBuilder path(String path)
This method sets the path of the uri.- Parameters:
path
- the path after the port and for the query in a uri- Returns:
- the builder instance
-
version
public String version()
- Returns:
- the version
-
version
public Http.RequestBuilder version(String version)
- Parameters:
version
- the version- Returns:
- the builder instance
-
getHeaders
public Http.Headers getHeaders()
Deprecated.Deprecated as of 2.9.0. Renamed toheaders()
.- Returns:
- the headers for this request builder
-
headers
public Http.Headers headers()
- Returns:
- the headers for this request builder
-
headers
public Http.RequestBuilder headers(Http.Headers headers)
Set the headers to be used by the request builder.- Parameters:
headers
- the headers to be replaced- Returns:
- the builder instance
-
header
public Http.RequestBuilder header(String key, List<String> values)
- Parameters:
key
- the key for in the headervalues
- the values associated with the key- Returns:
- the builder instance
-
header
public Http.RequestBuilder header(String key, String value)
- Parameters:
key
- the key for in the headervalue
- the value (one) associated with the key- Returns:
- the builder instance
-
cookies
public Http.Cookies cookies()
- Returns:
- the cookies in Java instances
-
cookie
public Http.RequestBuilder cookie(Http.Cookie cookie)
Sets one cookie.- Parameters:
cookie
- the cookie to be set- Returns:
- the builder instance
-
flash
public Http.RequestBuilder flash(String key, String value)
Sets a cookie in the request.- Parameters:
key
- the key for the cookievalue
- the value for the cookie- Returns:
- the builder instance
-
flash
public Http.RequestBuilder flash(Map<String,String> data)
Sets cookies in a request.- Parameters:
data
- a key value mapping of cookies- Returns:
- the builder instance
-
session
public Http.RequestBuilder session(String key, String value)
Sets a session.- Parameters:
key
- the key for the sessionvalue
- the value associated with the key for the session- Returns:
- the builder instance
-
session
public Http.RequestBuilder session(Map<String,String> data)
Sets all parameters for the session.- Parameters:
data
- a key value mapping of the session data- Returns:
- the builder instance
-
remoteAddress
public String remoteAddress()
- Returns:
- the remote address
-
remoteAddress
public Http.RequestBuilder remoteAddress(String remoteAddress)
- Parameters:
remoteAddress
- sets the remote address- Returns:
- the builder instance
-
clientCertificateChain
public Optional<List<X509Certificate>> clientCertificateChain()
- Returns:
- the client X509Certificates if they have been set
-
clientCertificateChain
public Http.RequestBuilder clientCertificateChain(List<X509Certificate> clientCertificateChain)
- Parameters:
clientCertificateChain
- sets the X509Certificates to use- Returns:
- the builder instance
-
langCookie
public Http.RequestBuilder langCookie(Lang lang, MessagesApi messagesApi)
Sets given lang in a cookie.- Parameters:
lang
- The language to use.- Returns:
- the builder instance
-
langCookie
public Http.RequestBuilder langCookie(Locale locale, MessagesApi messagesApi)
Sets given lang in a cookie.- Parameters:
locale
- The language to use.- Returns:
- the builder instance
-
transientLang
public Http.RequestBuilder transientLang(Lang lang)
Sets the transient language.- Parameters:
lang
- The language to use.- Returns:
- the builder instance
-
transientLang
@Deprecated public Http.RequestBuilder transientLang(String code)
Deprecated.Deprecated as of 2.8.0 UsetransientLang(Lang)
instead.Sets the transient language.- Parameters:
code
- The language to use.- Returns:
- the builder instance
-
transientLang
public Http.RequestBuilder transientLang(Locale locale)
Sets the transient language.- Parameters:
locale
- The language to use.- Returns:
- the builder instance
-
withoutTransientLang
public Http.RequestBuilder withoutTransientLang()
Removes the transient language.- Returns:
- the builder instance
-
-