Class HttpRequest
- java.lang.Object
-
- com.yahoo.jdisc.AbstractResource
-
- com.yahoo.jdisc.Request
-
- com.yahoo.jdisc.http.HttpRequest
-
- All Implemented Interfaces:
com.yahoo.jdisc.SharedResource
public class HttpRequest extends com.yahoo.jdisc.Request
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, URI uri, HttpRequest.Method method, HttpRequest.Version version, SocketAddress remoteAddress, Long connectedAtMillis)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
copyHeaders(com.yahoo.jdisc.HeaderFields target)
List<Cookie>
decodeCookieHeader()
void
encodeCookieHeader(List<Cookie> cookies)
long
getConnectedAt(TimeUnit unit)
For server requests, this returns the timestamp of when the underlying HTTP channel was connected.Long
getConnectionTimeout(TimeUnit unit)
HttpRequest.Method
getMethod()
URI
getProxyServer()
SocketAddress
getRemoteAddress()
String
getRemoteHostAddress()
Returns the remote address, or null if unresolvedString
getRemoteHostName()
int
getRemotePort()
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, URI uri)
static HttpRequest
newClientRequest(com.yahoo.jdisc.Request parent, URI uri, HttpRequest.Method method)
static HttpRequest
newClientRequest(com.yahoo.jdisc.Request parent, URI uri, HttpRequest.Method method, HttpRequest.Version version)
static HttpRequest
newServerRequest(com.yahoo.jdisc.service.CurrentContainer container, URI uri)
static HttpRequest
newServerRequest(com.yahoo.jdisc.service.CurrentContainer container, URI uri, HttpRequest.Method method)
static HttpRequest
newServerRequest(com.yahoo.jdisc.service.CurrentContainer container, URI uri, HttpRequest.Method method, HttpRequest.Version version)
static HttpRequest
newServerRequest(com.yahoo.jdisc.service.CurrentContainer container, URI uri, HttpRequest.Method method, HttpRequest.Version version, SocketAddress remoteAddress)
static HttpRequest
newServerRequest(com.yahoo.jdisc.service.CurrentContainer container, URI uri, HttpRequest.Method method, HttpRequest.Version version, SocketAddress remoteAddress, long connectedAtMillis)
Map<String,List<String>>
parameters()
long
relativeCreatedAtNanoTime()
void
setConnectionTimeout(long timeout, 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(URI proxyServer)
void
setRemoteAddress(SocketAddress remoteAddress)
void
setUserPrincipal(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
-
-
-
-
Constructor Detail
-
HttpRequest
protected HttpRequest(com.yahoo.jdisc.service.CurrentContainer container, URI uri, HttpRequest.Method method, HttpRequest.Version version, SocketAddress remoteAddress, Long connectedAtMillis)
-
-
Method Detail
-
getMethod
public HttpRequest.Method getMethod()
-
setMethod
public void setMethod(HttpRequest.Method method)
-
getVersion
public HttpRequest.Version getVersion()
-
getRemoteHostAddress
public String getRemoteHostAddress()
Returns the remote address, or null if unresolved
-
getRemoteHostName
public String getRemoteHostName()
-
getRemotePort
public int getRemotePort()
-
setVersion
public void setVersion(HttpRequest.Version version)
-
getRemoteAddress
public SocketAddress getRemoteAddress()
-
setRemoteAddress
public void setRemoteAddress(SocketAddress remoteAddress)
-
getProxyServer
public URI getProxyServer()
-
setProxyServer
public void setProxyServer(URI proxyServer)
-
getConnectedAt
public long getConnectedAt(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)
.- Parameters:
unit
- the unit to return the time in- Returns:
- the timestamp of when the underlying HTTP channel was connected, or request creation time
-
setConnectionTimeout
public void setConnectionTimeout(long timeout, 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.
-
copyHeaders
public void copyHeaders(com.yahoo.jdisc.HeaderFields target)
-
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()
-
relativeCreatedAtNanoTime
public long relativeCreatedAtNanoTime()
- Returns:
- the relative created timestamp (using
System.nanoTime()
-
getUserPrincipal
public Principal getUserPrincipal()
-
setUserPrincipal
public void setUserPrincipal(Principal principal)
-
newServerRequest
public static HttpRequest newServerRequest(com.yahoo.jdisc.service.CurrentContainer container, URI uri)
-
newServerRequest
public static HttpRequest newServerRequest(com.yahoo.jdisc.service.CurrentContainer container, URI uri, HttpRequest.Method method)
-
newServerRequest
public static HttpRequest newServerRequest(com.yahoo.jdisc.service.CurrentContainer container, URI uri, HttpRequest.Method method, HttpRequest.Version version)
-
newServerRequest
public static HttpRequest newServerRequest(com.yahoo.jdisc.service.CurrentContainer container, URI uri, HttpRequest.Method method, HttpRequest.Version version, SocketAddress remoteAddress)
-
newServerRequest
public static HttpRequest newServerRequest(com.yahoo.jdisc.service.CurrentContainer container, URI uri, HttpRequest.Method method, HttpRequest.Version version, SocketAddress remoteAddress, long connectedAtMillis)
-
newClientRequest
public static HttpRequest newClientRequest(com.yahoo.jdisc.Request parent, URI uri)
-
newClientRequest
public static HttpRequest newClientRequest(com.yahoo.jdisc.Request parent, URI uri, HttpRequest.Method method)
-
newClientRequest
public static HttpRequest newClientRequest(com.yahoo.jdisc.Request parent, URI uri, HttpRequest.Method method, HttpRequest.Version version)
-
-