Package play.mvc
Class Http.RequestBuilder
java.lang.Object
play.mvc.Http.RequestBuilder
- Enclosing class:
- Http
The builder for building a request.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionReturns a simple request builder.RequestBuilder(play.api.mvc.request.RequestFactory requestFactory) Returns a simple request builder.Returns a request builder as copy of the passed request builder. -
Method Summary
Modifier and TypeMethodDescriptionAdd an attribute to the request.attrs()Update the request attributes.body()protected Http.RequestBuilderbody(Http.RequestBody body) Set the body of the request.protected Http.RequestBuilderbody(Http.RequestBody body, String contentType) Set the body of the request.Set a Form url encoded body to this request.bodyFormArrayValues(Map<String, String[]> data) Set a Form url encoded body to this request.bodyJson(com.fasterxml.jackson.databind.JsonNode node) Set a Json Body to this request.bodyJson(play.api.libs.json.JsValue json) Set a Json Body to this request.bodyMultipart(List<Http.MultipartFormData.Part<Source<ByteString, ?>>> data, Files.TemporaryFileCreator temporaryFileCreator, Materializer mat) Deprecated.Deprecated as of 2.7.0.bodyMultipart(Map<String, String[]> formData, List<Http.MultipartFormData.FilePart> files) Set a Multipart Form url encoded body to this request.bodyRaw(byte[] data) Set a Binary Data to this request using a singleton temporary file creator.bodyRaw(byte[] data, Files.TemporaryFileCreator tempFileCreator) Set a Binary Data to this request.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.bodyRaw(ByteString data) Set a Binary Data to this request using a singleton temp file creator TheContent-Typeheader of the request is set toapplication/octet-stream.bodyRaw(ByteString data, Files.TemporaryFileCreator tempFileCreator) Set a Binary Data to this request.Set a Text to this request.Set a Text to this request.Set a XML to this request.bodyXml(InputSource xml) Set a XML to this request.build()Builds the request.clientCertificateChain(List<X509Certificate> clientCertificateChain) cookie(Http.Cookie cookie) Sets one cookie.cookies()flash()Sets a cookie in the request.Sets cookies in a request.Deprecated.Deprecated as of 2.9.0.headers()headers(Http.Headers headers) Set the headers to be used by the request builder.host()id()langCookie(Locale locale, MessagesApi messagesApi) Sets given lang in a cookie.langCookie(Lang lang, MessagesApi messagesApi) Sets given lang in a cookie.method()path()This method sets the path of the uri.remoteAddress(String remoteAddress) booleansecure()secure(boolean secure) session()Sets a session.Sets all parameters for the session.transientLang(String code) Deprecated.Deprecated as of 2.8.0 UsetransientLang(Lang)instead.transientLang(Locale locale) Sets the transient language.transientLang(Lang lang) Sets the transient language.uri()Sets the uri.version()Removes the transient language.
-
Field Details
-
req
-
-
Constructor Details
-
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
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 Details
-
body
- Returns:
- the request body, if a previously the body has been set
-
body
Set the body of the request.- Parameters:
body- the bodycontentType- Content-Type header value- Returns:
- the modified builder
-
body
Set the body of the request.- Parameters:
body- The body.- Returns:
- the modified builder
-
bodyRaw
Set a Binary Data to this request using a singleton temp file creator TheContent-Typeheader of the request is set toapplication/octet-stream.- Parameters:
data- the Binary Data- Returns:
- the modified builder
-
bodyRaw
Set a Binary Data to this request. TheContent-Typeheader 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
Set a Binary Data to this request using a singleton temporary file creator. TheContent-Typeheader of the request is set toapplication/octet-stream.- Parameters:
data- the Binary Data- Returns:
- the modified builder
-
bodyRaw
Set a Binary Data to this request. TheContent-Typeheader 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
Set a Form url encoded body to this request.- Parameters:
data- the x-www-form-urlencoded parameters- Returns:
- the modified builder
-
bodyForm
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 Pekko 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 Pekko 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
Set a Json Body to this request. TheContent-Typeheader of the request is set toapplication/json.- Parameters:
node- the Json Node- Returns:
- this builder, updated
-
bodyJson
Set a Json Body to this request. TheContent-Typeheader of the request is set toapplication/json.- Parameters:
json- the JsValue- Returns:
- the modified builder
-
bodyXml
Set a XML to this request. TheContent-Typeheader of the request is set toapplication/xml.- Parameters:
xml- the XML- Returns:
- the modified builder
-
bodyXml
Set a XML to this request.The
Content-Typeheader of the request is set toapplication/xml.- Parameters:
xml- the XML- Returns:
- the modified builder
-
bodyText
Set a Text to this request. TheContent-Typeheader 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
Set a Text to this request. TheContent-Typeheader 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
Builds the request.- Returns:
- a build of the given parameters
-
id
- Returns:
- the id of the request
-
id
- Parameters:
id- the id to be used- Returns:
- the builder instance
-
attr
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
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
- Returns:
- the request builder's request attributes.
-
method
- Returns:
- the builder instance.
-
method
- Parameters:
method- sets the method- Returns:
- the builder instance
-
uri
- Returns:
- gives the uri of the request
-
uri
-
uri
Sets the uri.- Parameters:
str- the uri- Returns:
- the builder instance
-
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
- Returns:
- the host name from the header
-
host
- Parameters:
host- sets the host in the header- Returns:
- the builder instance
-
path
- Returns:
- the raw path of the uri
-
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
- Returns:
- the version
-
version
- Parameters:
version- the version- Returns:
- the builder instance
-
getHeaders
Deprecated.Deprecated as of 2.9.0. Renamed toheaders().- Returns:
- the headers for this request builder
-
headers
- Returns:
- the headers for this request builder
-
headers
Set the headers to be used by the request builder.- Parameters:
headers- the headers to be replaced- Returns:
- the builder instance
-
header
- Parameters:
key- the key for in the headervalues- the values associated with the key- Returns:
- the builder instance
-
header
- Parameters:
key- the key for in the headervalue- the value (one) associated with the key- Returns:
- the builder instance
-
cookies
- Returns:
- the cookies in Java instances
-
cookie
Sets one cookie.- Parameters:
cookie- the cookie to be set- Returns:
- the builder instance
-
flash
- Returns:
- the cookies in a Java map
-
flash
Sets a cookie in the request.- Parameters:
key- the key for the cookievalue- the value for the cookie- Returns:
- the builder instance
-
flash
Sets cookies in a request.- Parameters:
data- a key value mapping of cookies- Returns:
- the builder instance
-
session
- Returns:
- the sessions in the request
-
session
Sets a session.- Parameters:
key- the key for the sessionvalue- the value associated with the key for the session- Returns:
- the builder instance
-
session
Sets all parameters for the session.- Parameters:
data- a key value mapping of the session data- Returns:
- the builder instance
-
remoteAddress
- Returns:
- the remote address
-
remoteAddress
- Parameters:
remoteAddress- sets the remote address- Returns:
- the builder instance
-
clientCertificateChain
- Returns:
- the client X509Certificates if they have been set
-
clientCertificateChain
- Parameters:
clientCertificateChain- sets the X509Certificates to use- Returns:
- the builder instance
-
langCookie
Sets given lang in a cookie.- Parameters:
lang- The language to use.- Returns:
- the builder instance
-
langCookie
Sets given lang in a cookie.- Parameters:
locale- The language to use.- Returns:
- the builder instance
-
transientLang
Sets the transient language.- Parameters:
lang- The language to use.- Returns:
- the builder instance
-
transientLang
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
Sets the transient language.- Parameters:
locale- The language to use.- Returns:
- the builder instance
-
withoutTransientLang
Removes the transient language.- Returns:
- the builder instance
-