Package play.mvc

Class Http.RequestBuilder

  • Enclosing class:
    Http

    public static class Http.RequestBuilder
    extends Object
    The builder for building a request.
    • 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 body
        contentType - Content-Type header value
        Returns:
        the modified builder
      • bodyRaw

        public Http.RequestBuilder bodyRaw​(ByteString data)
        Set a Binary Data to this request using a singleton temp file creator The Content-Type header of the request is set to application/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. The Content-Type header of the request is set to application/octet-stream.
        Parameters:
        data - the Binary Data
        tempFileCreator - 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. The Content-Type header of the request is set to application/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. The Content-Type header of the request is set to application/octet-stream.
        Parameters:
        data - the Binary Data
        tempFileCreator - 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
      • bodyJson

        public Http.RequestBuilder bodyJson​(com.fasterxml.jackson.databind.JsonNode node)
        Set a Json Body to this request. The Content-Type header of the request is set to application/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. The Content-Type header of the request is set to application/json.
        Parameters:
        json - the JsValue
        Returns:
        the modified builder
      • bodyXml

        public Http.RequestBuilder bodyXml​(InputSource xml)
        Set a XML to this request. The Content-Type header of the request is set to application/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 to application/xml.

        Parameters:
        xml - the XML
        Returns:
        the modified builder
      • bodyText

        public Http.RequestBuilder bodyText​(String text)
        Set a Text to this request. The Content-Type header of the request is set to text/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. The Content-Type header of the request is set to text/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
      • 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
      • 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 to headers().
        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 header
        values - 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 header
        value - 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 Map<String,​String> flash()
        Returns:
        the cookies in a Java map
      • flash

        public Http.RequestBuilder flash​(String key,
                                         String value)
        Sets a cookie in the request.
        Parameters:
        key - the key for the cookie
        value - 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 Map<String,​String> session()
        Returns:
        the sessions in the request
      • session

        public Http.RequestBuilder session​(String key,
                                           String value)
        Sets a session.
        Parameters:
        key - the key for the session
        value - 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

        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