Class HttpRequest
- java.lang.Object
-
- com.yahoo.jdisc.AbstractResource
-
- com.yahoo.jdisc.Request
-
- com.yahoo.jdisc.http.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
HttpRequest.Method
static class
HttpRequest.Version
-
Constructor Summary
Constructors Modifier Constructor Description 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 Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
copyHeaders(com.yahoo.jdisc.HeaderFields target)
java.util.List<Cookie>
decodeCookieHeader()
void
encodeCookieHeader(java.util.List<Cookie> cookies)
long
getConnectedAt(java.util.concurrent.TimeUnit unit)
For server requests, this returns the timestamp of when the underlying HTTP channel was connected.java.lang.Long
getConnectionTimeout(java.util.concurrent.TimeUnit unit)
HttpRequest.Method
getMethod()
java.net.URI
getProxyServer()
java.net.SocketAddress
getRemoteAddress()
java.lang.String
getRemoteHostAddress()
Returns the remote address, or null if unresolvedjava.lang.String
getRemoteHostName()
int
getRemotePort()
java.security.Principal
getUserPrincipal()
HttpRequest.Version
getVersion()
boolean
hasChunkedResponse()
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.boolean
isKeepAlive()
static HttpRequest
newClientRequest(com.yahoo.jdisc.Request parent, java.net.URI uri)
static HttpRequest
newClientRequest(com.yahoo.jdisc.Request parent, java.net.URI uri, HttpRequest.Method method)
static HttpRequest
newClientRequest(com.yahoo.jdisc.Request parent, java.net.URI uri, HttpRequest.Method method, HttpRequest.Version version)
static HttpRequest
newServerRequest(com.yahoo.jdisc.service.CurrentContainer container, java.net.URI uri)
static HttpRequest
newServerRequest(com.yahoo.jdisc.service.CurrentContainer container, java.net.URI uri, HttpRequest.Method method)
static HttpRequest
newServerRequest(com.yahoo.jdisc.service.CurrentContainer container, java.net.URI uri, HttpRequest.Method method, HttpRequest.Version version)
static HttpRequest
newServerRequest(com.yahoo.jdisc.service.CurrentContainer container, java.net.URI uri, HttpRequest.Method method, HttpRequest.Version version, java.net.SocketAddress remoteAddress)
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)
java.util.Map<java.lang.String,java.util.List<java.lang.String>>
parameters()
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.void
setMethod(HttpRequest.Method method)
void
setProxyServer(java.net.URI proxyServer)
void
setRemoteAddress(java.net.SocketAddress remoteAddress)
void
setUserPrincipal(java.security.Principal principal)
void
setVersion(HttpRequest.Version version)
com.yahoo.jdisc.HeaderFields
trailers()
Returns the set of trailer header fields of this HttpRequest.-
Methods inherited from class com.yahoo.jdisc.Request
cancel, connect, container, context, creationTime, destroy, getBindingMatch, getTimeout, getTimeoutManager, getUri, headers, isCancelled, isServerRequest, setBindingMatch, setServerRequest, setTimeout, setTimeoutManager, setUri, timeElapsed, timeRemaining
-
Methods inherited from class com.yahoo.jdisc.AbstractResource
currentState, refer, release, retainCount
-
-
-
-
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
-
getMethod
public HttpRequest.Method getMethod()
-
setMethod
public void setMethod(HttpRequest.Method method)
-
getVersion
public HttpRequest.Version getVersion()
- Specified by:
getVersion
in interfacecom.yahoo.jdisc.http.servlet.ServletOrJdiscHttpRequest
-
getRemoteHostAddress
public java.lang.String getRemoteHostAddress()
Returns the remote address, or null if unresolved- Specified by:
getRemoteHostAddress
in interfacecom.yahoo.jdisc.http.servlet.ServletOrJdiscHttpRequest
-
getRemoteHostName
public java.lang.String getRemoteHostName()
- Specified by:
getRemoteHostName
in interfacecom.yahoo.jdisc.http.servlet.ServletOrJdiscHttpRequest
-
getRemotePort
public int getRemotePort()
- Specified by:
getRemotePort
in interfacecom.yahoo.jdisc.http.servlet.ServletOrJdiscHttpRequest
-
setVersion
public void setVersion(HttpRequest.Version version)
-
getRemoteAddress
public java.net.SocketAddress getRemoteAddress()
-
setRemoteAddress
public void setRemoteAddress(java.net.SocketAddress remoteAddress)
- Specified by:
setRemoteAddress
in interfacecom.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 interfacecom.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 aResponseHandler
, 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 interfacecom.yahoo.jdisc.http.servlet.ServletOrJdiscHttpRequest
-
copyHeaders
public void copyHeaders(com.yahoo.jdisc.HeaderFields target)
- Specified by:
copyHeaders
in interfacecom.yahoo.jdisc.http.servlet.ServletOrJdiscHttpRequest
-
decodeCookieHeader
public java.util.List<Cookie> decodeCookieHeader()
- Specified by:
decodeCookieHeader
in interfacecom.yahoo.jdisc.http.servlet.ServletOrJdiscHttpRequest
-
encodeCookieHeader
public void encodeCookieHeader(java.util.List<Cookie> cookies)
- Specified by:
encodeCookieHeader
in interfacecom.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 callingRequest.connect(ResponseHandler)
. You must NOT WRITE to these headers AFTER callingContentChannel.close(CompletionHandler)
, and you must NOT READ from these headers BEFOREContentChannel.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 forContentChannel.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)
-
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)
-
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)
-
newClientRequest
public static HttpRequest newClientRequest(com.yahoo.jdisc.Request parent, java.net.URI uri, HttpRequest.Method method, HttpRequest.Version version)
-
-