Class HttpRequest

    • Method Detail

      • getScheme

        public java.lang.String getScheme()
        Specified by:
        getScheme in interface Request
        Returns:
        the URI scheme of this request, such as "http" or "https"
      • scheme

        public Request scheme​(java.lang.String scheme)
        Specified by:
        scheme in interface Request
        Parameters:
        scheme - the URI scheme of this request, such as "http" or "https"
        Returns:
        this request object
      • getHost

        public java.lang.String getHost()
        Specified by:
        getHost in interface Request
        Returns:
        the URI host of this request, such as "127.0.0.1" or "google.com"
      • host

        public Request host​(java.lang.String host)
        Specified by:
        host in interface Request
        Parameters:
        host - the URI host of this request, such as "127.0.0.1" or "google.com"
        Returns:
        this request object
      • getPort

        public int getPort()
        Specified by:
        getPort in interface Request
        Returns:
        the URI port of this request such as 80 or 443
      • port

        public Request port​(int port)
        Specified by:
        port in interface Request
        Parameters:
        port - the URI port of this request such as 80 or 443
        Returns:
        this request object
      • getMethod

        public java.lang.String getMethod()
        Specified by:
        getMethod in interface Request
        Returns:
        the method of this request, such as GET or POST, as a String
      • method

        public Request method​(HttpMethod method)
        Specified by:
        method in interface Request
        Parameters:
        method - the method of this request, such as GET or POST
        Returns:
        this request object
      • method

        public Request method​(java.lang.String method)
        Specified by:
        method in interface Request
        Parameters:
        method - the method of this request, such as GET or POST
        Returns:
        this request object
      • getPath

        public java.lang.String getPath()
        Specified by:
        getPath in interface Request
        Returns:
        the URI path of this request, such as "/" or "/path" - without the query
        See Also:
        Request.getQuery()
      • path

        public Request path​(java.lang.String path)
        Description copied from interface: Request
        Specifies the URI path - and possibly the query - of this request. If the query part is specified, parameter values must be properly UTF-8 URL encoded. For example, if the value for parameter "currency" is the euro symbol € then the query string for this parameter must be "currency=%E2%82%AC". For transparent encoding of parameter values, use Request.param(String, String).
        Specified by:
        path in interface Request
        Parameters:
        path - the URI path of this request, such as "/" or "/path?param=1"
        Returns:
        this request object
      • getURI

        public java.net.URI getURI()
        Specified by:
        getURI in interface Request
        Returns:
        the full URI of this request such as "http://host:port/path?param=1"
      • getVersion

        public HttpVersion getVersion()
        Specified by:
        getVersion in interface Request
        Returns:
        the HTTP version of this request, such as "HTTP/1.1"
      • version

        public Request version​(HttpVersion version)
        Specified by:
        version in interface Request
        Parameters:
        version - the HTTP version of this request, such as "HTTP/1.1"
        Returns:
        this request object
      • param

        public Request param​(java.lang.String name,
                             java.lang.String value)
        Description copied from interface: Request
        Adds a URI query parameter with the given name and value. The value is UTF-8 URL encoded.
        Specified by:
        param in interface Request
        Parameters:
        name - the name of the query parameter
        value - the value of the query parameter
        Returns:
        this request object
      • getParams

        public Fields getParams()
        Specified by:
        getParams in interface Request
        Returns:
        the URI query parameters of this request
      • getAgent

        public java.lang.String getAgent()
        Specified by:
        getAgent in interface Request
        Returns:
        the user agent for this request
      • agent

        public Request agent​(java.lang.String agent)
        Specified by:
        agent in interface Request
        Parameters:
        agent - the user agent for this request (corresponds to the User-Agent header)
        Returns:
        this request object
      • accept

        public Request accept​(java.lang.String... accepts)
        Specified by:
        accept in interface Request
        Parameters:
        accepts - the media types that are acceptable in the response, such as "text/plain;q=0.5" or "text/html" (corresponds to the Accept header)
        Returns:
        this request object
      • header

        public Request header​(java.lang.String name,
                              java.lang.String value)
        Specified by:
        header in interface Request
        Parameters:
        name - the name of the header
        value - the value of the header
        Returns:
        this request object
        See Also:
        Request.header(HttpHeader, String)
      • header

        public Request header​(HttpHeader header,
                              java.lang.String value)
        Description copied from interface: Request

        Adds the given value to the specified header.

        Multiple calls with the same parameters will add multiple values; use the value null to remove the header completely.

        Specified by:
        header in interface Request
        Parameters:
        header - the header name
        value - the value of the header
        Returns:
        this request object
      • getCookies

        public java.util.List<java.net.HttpCookie> getCookies()
        Specified by:
        getCookies in interface Request
        Returns:
        the cookies associated with this request
      • cookie

        public Request cookie​(java.net.HttpCookie cookie)
        Specified by:
        cookie in interface Request
        Parameters:
        cookie - a cookie for this request
        Returns:
        this request object
      • tag

        public Request tag​(java.lang.Object tag)
        Description copied from interface: Request

        Tags this request with the given metadata tag.

        Each different tag will create a different destination, even if the destination origin is the same.

        This is particularly useful in proxies, where requests for the same origin but from different clients may be tagged with client's metadata (e.g. the client remote address).

        The tag metadata class must correctly implement Object.hashCode() and Object.equals(Object) so that it can be used, along with the origin, to identify a destination.

        Specified by:
        tag in interface Request
        Parameters:
        tag - the metadata to tag the request with
        Returns:
        this request object
      • getTag

        public java.lang.Object getTag()
        Specified by:
        getTag in interface Request
        Returns:
        the metadata this request has been tagged with
      • attribute

        public Request attribute​(java.lang.String name,
                                 java.lang.Object value)
        Specified by:
        attribute in interface Request
        Parameters:
        name - the name of the attribute
        value - the value of the attribute
        Returns:
        this request object
      • getAttributes

        public java.util.Map<java.lang.String,​java.lang.Object> getAttributes()
        Specified by:
        getAttributes in interface Request
        Returns:
        the attributes of this request
      • getRequestListeners

        public <T extends Request.RequestListener> java.util.List<T> getRequestListeners​(java.lang.Class<T> type)
        Specified by:
        getRequestListeners in interface Request
        Type Parameters:
        T - the type of listener class
        Parameters:
        type - the class of the listener, or null for all listeners classes
        Returns:
        the listeners for request events of the given class
      • listener

        public Request listener​(Request.Listener listener)
        Specified by:
        listener in interface Request
        Parameters:
        listener - a listener for request events
        Returns:
        this request object
      • pushListener

        public Request pushListener​(java.util.function.BiFunction<Request,​Request,​Response.CompleteListener> listener)

        Sets a listener for pushed resources.

        When resources are pushed from the server, the given listener is invoked for every pushed resource. The parameters to the BiFunction are this request and the synthesized request for the pushed resource. The BiFunction should return a CompleteListener that may also implement other listener interfaces to be notified of various response events, or null to signal that the pushed resource should be canceled.

        Parameters:
        listener - a listener for pushed resource events
        Returns:
        this request object
      • content

        public Request content​(ContentProvider content)
        Specified by:
        content in interface Request
        Parameters:
        content - the content provider of this request
        Returns:
        this request object
      • content

        public Request content​(ContentProvider content,
                               java.lang.String contentType)
        Specified by:
        content in interface Request
        Parameters:
        content - the content provider of this request
        contentType - the content type
        Returns:
        this request object
      • file

        public Request file​(java.nio.file.Path file)
                     throws java.io.IOException
        Description copied from interface: Request
        Shortcut method to specify a file as a content for this request, with the default content type of "application/octect-stream".
        Specified by:
        file in interface Request
        Parameters:
        file - the file to upload
        Returns:
        this request object
        Throws:
        java.io.IOException - if the file does not exist or cannot be read
      • file

        public Request file​(java.nio.file.Path file,
                            java.lang.String contentType)
                     throws java.io.IOException
        Description copied from interface: Request
        Shortcut method to specify a file as a content for this request, with the given content type.
        Specified by:
        file in interface Request
        Parameters:
        file - the file to upload
        contentType - the content type of the file
        Returns:
        this request object
        Throws:
        java.io.IOException - if the file does not exist or cannot be read
      • isFollowRedirects

        public boolean isFollowRedirects()
        Specified by:
        isFollowRedirects in interface Request
        Returns:
        whether this request follows redirects
      • followRedirects

        public Request followRedirects​(boolean follow)
        Specified by:
        followRedirects in interface Request
        Parameters:
        follow - whether this request follows redirects
        Returns:
        this request object
      • getIdleTimeout

        public long getIdleTimeout()
        Specified by:
        getIdleTimeout in interface Request
        Returns:
        the idle timeout for this request, in milliseconds
      • idleTimeout

        public Request idleTimeout​(long timeout,
                                   java.util.concurrent.TimeUnit unit)
        Specified by:
        idleTimeout in interface Request
        Parameters:
        timeout - the idle timeout for this request
        unit - the idle timeout unit
        Returns:
        this request object
      • getTimeout

        public long getTimeout()
        Specified by:
        getTimeout in interface Request
        Returns:
        the total timeout for this request, in milliseconds; zero or negative if the timeout is disabled
      • timeout

        public Request timeout​(long timeout,
                               java.util.concurrent.TimeUnit unit)
        Specified by:
        timeout in interface Request
        Parameters:
        timeout - the total timeout for the request/response conversation; use zero or a negative value to disable the timeout
        unit - the timeout unit
        Returns:
        this request object
      • send

        public ContentResponse send()
                             throws java.lang.InterruptedException,
                                    java.util.concurrent.TimeoutException,
                                    java.util.concurrent.ExecutionException
        Description copied from interface: Request
        Sends this request and returns the response.

        This method should be used when a simple blocking semantic is needed, and when it is known that the response content can be buffered without exceeding memory constraints.

        For example, this method is not appropriate to download big files from a server; consider using Request.send(Response.CompleteListener) instead, passing your own Response.Listener or a utility listener such as InputStreamResponseListener.

        The method returns when the complete event is fired.

        Specified by:
        send in interface Request
        Returns:
        a ContentResponse for this request
        Throws:
        java.lang.InterruptedException - if send thread is interrupted
        java.util.concurrent.TimeoutException - if send times out
        java.util.concurrent.ExecutionException - if execution fails
        See Also:
        Response.CompleteListener.onComplete(Result)
      • send

        public void send​(Response.CompleteListener listener)
        Description copied from interface: Request

        Sends this request and asynchronously notifies the given listener for response events.

        This method should be used when the application needs to be notified of the various response events as they happen, or when the application needs to efficiently manage the response content.

        The listener passed to this method may implement not only Response.CompleteListener but also other response listener interfaces, and all the events implemented will be notified. This allows application code to write a single listener class to handle all relevant events.

        Specified by:
        send in interface Request
        Parameters:
        listener - the listener that receives response events
      • getTrailers

        public java.util.function.Supplier<HttpFields> getTrailers()
      • abort

        public boolean abort​(java.lang.Throwable cause)
        Description copied from interface: Request
        Attempts to abort the send of this request.
        Specified by:
        abort in interface Request
        Parameters:
        cause - the abort cause, must not be null
        Returns:
        whether the abort succeeded
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object