public class HttpEngine extends Object
The request and response may be served by the HTTP response cache, by the network, or by both in the event of a conditional GET.
This class may hold a socket connection that needs to be released or
recycled. By default, this socket connection is held when the last byte of
the response is consumed. To release the connection when it is no longer
required, use automaticallyReleaseConnectionToPool()
.
Modifier and Type | Field and Description |
---|---|
protected Connection |
connection |
static int |
HTTP_CONTINUE |
protected String |
method |
protected HttpURLConnectionImpl |
policy |
protected RouteSelector |
routeSelector |
Constructor and Description |
---|
HttpEngine(HttpURLConnectionImpl policy,
String method,
RawHeaders requestHeaders,
Connection connection,
com.squareup.okhttp.internal.http.RetryableOutputStream requestBodyOut) |
Modifier and Type | Method and Description |
---|---|
protected boolean |
acceptCacheResponseType(CacheResponse cacheResponse)
Returns true if
cacheResponse is of the right type. |
void |
automaticallyReleaseConnectionToPool()
Cause the socket connection to be released to the connection pool when
it is no longer needed.
|
protected void |
connect()
Connect to the origin server either directly or via a proxy.
|
protected void |
connected(Connection connection)
Called after a socket connection has been created or retrieved from the
pool.
|
CacheResponse |
getCacheResponse() |
Connection |
getConnection() |
static String |
getDefaultUserAgent() |
static String |
getOriginAddress(URL url) |
OutputStream |
getRequestBody()
Returns the request body or null if this request doesn't have a body.
|
RequestHeaders |
getRequestHeaders() |
InputStream |
getResponseBody() |
int |
getResponseCode() |
ResponseHeaders |
getResponseHeaders() |
protected TunnelRequest |
getTunnelConfig() |
URI |
getUri() |
boolean |
hasResponse() |
boolean |
hasResponseBody()
Returns true if the response must have a (possibly 0-length) body.
|
protected boolean |
includeAuthorityInRequestLine()
Returns true if the request line should contain the full URL with host
and port (like "GET http://android.com/foo HTTP/1.1") or only the path
(like "GET /foo HTTP/1.1").
|
void |
readResponse()
Flushes the remaining request header and body, parses the HTTP response
headers and starts reading the HTTP response body if it exists.
|
void |
receiveHeaders(RawHeaders headers) |
void |
release(boolean streamCancelled)
Releases this engine so that its resources may be either reused or
closed.
|
static String |
requestPath(URL url)
Returns the path to request, like the '/' in 'GET / HTTP/1.1'.
|
void |
sendRequest()
Figures out what the response source will be, and opens a socket to that
source if necessary.
|
void |
writingRequestHeaders()
Called immediately before the transport transmits HTTP request headers.
|
public static final int HTTP_CONTINUE
protected final HttpURLConnectionImpl policy
protected final String method
protected Connection connection
protected RouteSelector routeSelector
public HttpEngine(HttpURLConnectionImpl policy, String method, RawHeaders requestHeaders, Connection connection, com.squareup.okhttp.internal.http.RetryableOutputStream requestBodyOut) throws IOException
requestHeaders
- the client's supplied request headers. This class
creates a private copy that it can mutate.connection
- the connection used for an intermediate response
immediately prior to this request/response pair, such as a same-host
redirect. This engine assumes ownership of the connection and must
release it when it is unneeded.IOException
public URI getUri()
public final void sendRequest() throws IOException
IOException
protected final void connect() throws IOException
IOException
protected void connected(Connection connection)
public void writingRequestHeaders()
public final OutputStream getRequestBody()
public final boolean hasResponse()
public final RequestHeaders getRequestHeaders()
public final ResponseHeaders getResponseHeaders()
public final int getResponseCode()
public final InputStream getResponseBody()
public final CacheResponse getCacheResponse()
public final Connection getConnection()
protected boolean acceptCacheResponseType(CacheResponse cacheResponse)
cacheResponse
is of the right type. This
condition is necessary but not sufficient for the cached response to
be used.public final void automaticallyReleaseConnectionToPool()
public final void release(boolean streamCancelled)
automaticallyReleaseConnectionToPool
unless
the connection will be used to follow a redirect.public final boolean hasResponseBody()
public static String requestPath(URL url)
protected boolean includeAuthorityInRequestLine()
This is non-final because for HTTPS it's never necessary to supply the full URL, even if a proxy is in use.
public static String getDefaultUserAgent()
public final void readResponse() throws IOException
IOException
protected TunnelRequest getTunnelConfig()
public void receiveHeaders(RawHeaders headers) throws IOException
IOException
Copyright © 2013. All Rights Reserved.