Class HttpRequest

  • All Implemented Interfaces:
    com.yahoo.jdisc.http.servlet.ServletOrJdiscHttpRequest, com.yahoo.jdisc.SharedResource

    public class HttpRequest
    extends com.yahoo.jdisc.Request
    implements com.yahoo.jdisc.http.servlet.ServletOrJdiscHttpRequest
    A HTTP request.
    Author:
    Anirudha Khanna, Einar M R Rosenvinge
    • Constructor Detail

      • HttpRequest

        protected HttpRequest​(com.yahoo.jdisc.service.CurrentContainer container,
                              java.net.URI uri,
                              HttpRequest.Method method,
                              HttpRequest.Version version,
                              java.net.SocketAddress remoteAddress,
                              java.lang.Long connectedAtMillis)
    • Method Detail

      • getVersion

        public HttpRequest.Version getVersion()
        Specified by:
        getVersion in interface com.yahoo.jdisc.http.servlet.ServletOrJdiscHttpRequest
      • getRemoteHostAddress

        public java.lang.String getRemoteHostAddress()
        Returns the remove address, or null if unresolved
        Specified by:
        getRemoteHostAddress in interface com.yahoo.jdisc.http.servlet.ServletOrJdiscHttpRequest
      • getRemoteHostName

        public java.lang.String getRemoteHostName()
        Specified by:
        getRemoteHostName in interface com.yahoo.jdisc.http.servlet.ServletOrJdiscHttpRequest
      • getRemotePort

        public int getRemotePort()
        Specified by:
        getRemotePort in interface com.yahoo.jdisc.http.servlet.ServletOrJdiscHttpRequest
      • getRemoteAddress

        public java.net.SocketAddress getRemoteAddress()
      • setRemoteAddress

        public void setRemoteAddress​(java.net.SocketAddress remoteAddress)
        Specified by:
        setRemoteAddress in interface com.yahoo.jdisc.http.servlet.ServletOrJdiscHttpRequest
      • getProxyServer

        public java.net.URI getProxyServer()
      • setProxyServer

        public void setProxyServer​(java.net.URI proxyServer)
      • getConnectedAt

        public long getConnectedAt​(java.util.concurrent.TimeUnit unit)

        For server requests, this returns the timestamp of when the underlying HTTP channel was connected.

        For client requests, this returns the same value as Request.creationTime(java.util.concurrent.TimeUnit).

        Specified by:
        getConnectedAt in interface com.yahoo.jdisc.http.servlet.ServletOrJdiscHttpRequest
        Parameters:
        unit - the unit to return the time in
        Returns:
        the timestamp of when the underlying HTTP channel was connected, or request creation time
      • getConnectionTimeout

        public java.lang.Long getConnectionTimeout​(java.util.concurrent.TimeUnit unit)
      • setConnectionTimeout

        public void setConnectionTimeout​(long timeout,
                                         java.util.concurrent.TimeUnit unit)

        Sets the allocated time that this HttpRequest is allowed to spend trying to connect to a remote host. This has no effect on an HttpRequest received by a RequestHandler. If no connection timeout is assigned to an HttpRequest, it defaults the connection-timeout in the client configuration.

        NOTE: Where Request.setTimeout(long, TimeUnit) sets the expiration time between calling a RequestHandler and a ResponseHandler, this method sets the expiration time of the connect-operation as performed by the client.

        Parameters:
        timeout - The allocated amount of time.
        unit - The time unit of the timeout argument.
      • parameters

        public java.util.Map<java.lang.String,​java.util.List<java.lang.String>> parameters()
        Specified by:
        parameters in interface com.yahoo.jdisc.http.servlet.ServletOrJdiscHttpRequest
      • copyHeaders

        public void copyHeaders​(com.yahoo.jdisc.HeaderFields target)
        Specified by:
        copyHeaders in interface com.yahoo.jdisc.http.servlet.ServletOrJdiscHttpRequest
      • decodeCookieHeader

        public java.util.List<Cookie> decodeCookieHeader()
        Specified by:
        decodeCookieHeader in interface com.yahoo.jdisc.http.servlet.ServletOrJdiscHttpRequest
      • encodeCookieHeader

        public void encodeCookieHeader​(java.util.List<Cookie> cookies)
        Specified by:
        encodeCookieHeader in interface com.yahoo.jdisc.http.servlet.ServletOrJdiscHttpRequest
      • trailers

        public com.yahoo.jdisc.HeaderFields trailers()

        Returns the set of trailer header fields of this HttpRequest. These are typically meta-data that should have been part of Request.headers(), but were not available prior to calling Request.connect(ResponseHandler). You must NOT WRITE to these headers AFTER calling ContentChannel.close(CompletionHandler), and you must NOT READ from these headers BEFORE ContentChannel.close(CompletionHandler) has been called.

        NOTE: These headers are NOT thread-safe. You need to explicitly synchronized on the returned object to prevent concurrency issues such as ConcurrentModificationExceptions.

        Returns:
        The trailer headers of this HttpRequest.
      • isChunked

        public boolean isChunked()
        Returns whether this request was explicitly chunked from the client. NOTE that there are cases where the underlying HTTP server library (Netty for the time being) will read the request in a chunked manner. An application MUST wait for ContentChannel.close(com.yahoo.jdisc.handler.CompletionHandler) before it can actually know that it has received the entire request.
        Returns:
        true if this request was chunked from the client.
      • hasChunkedResponse

        public boolean hasChunkedResponse()
      • isKeepAlive

        public boolean isKeepAlive()
      • getUserPrincipal

        public java.security.Principal getUserPrincipal()
      • setUserPrincipal

        public void setUserPrincipal​(java.security.Principal principal)
      • newServerRequest

        public static HttpRequest newServerRequest​(com.yahoo.jdisc.service.CurrentContainer container,
                                                   java.net.URI uri)
      • newServerRequest

        public static HttpRequest newServerRequest​(com.yahoo.jdisc.service.CurrentContainer container,
                                                   java.net.URI uri,
                                                   HttpRequest.Method method)
      • newServerRequest

        public static HttpRequest newServerRequest​(com.yahoo.jdisc.service.CurrentContainer container,
                                                   java.net.URI uri,
                                                   HttpRequest.Method method,
                                                   HttpRequest.Version version,
                                                   java.net.SocketAddress remoteAddress,
                                                   long connectedAtMillis)
      • newClientRequest

        public static HttpRequest newClientRequest​(com.yahoo.jdisc.Request parent,
                                                   java.net.URI uri)
      • newClientRequest

        public static HttpRequest newClientRequest​(com.yahoo.jdisc.Request parent,
                                                   java.net.URI uri,
                                                   HttpRequest.Method method)