public final 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.
Modifier and Type | Field and Description |
---|---|
boolean |
bufferRequestBody
True if the request body must be completely buffered before transmission;
false if it can be streamed.
|
static int |
MAX_FOLLOW_UPS
How many redirects and auth challenges should we attempt? Chrome follows 21 redirects; Firefox,
curl, and wget follow 20; Safari follows 16; and HTTP/1.0 recommends 5.
|
Constructor and Description |
---|
HttpEngine(OkHttpClient client,
Request request,
boolean bufferRequestBody,
boolean callerWritesRequestBody,
boolean forWebSocket,
Connection connection,
RouteSelector routeSelector,
RetryableSink requestBodyOut,
Response priorResponse) |
Modifier and Type | Method and Description |
---|---|
Connection |
close()
Release any resources held by this engine.
|
void |
disconnect()
Immediately closes the socket connection if it's currently held by this
engine.
|
Request |
followUpRequest()
Figures out the HTTP request to make in response to receiving this engine's
response.
|
okio.BufferedSink |
getBufferedRequestBody() |
Connection |
getConnection() |
Request |
getRequest() |
okio.Sink |
getRequestBody()
Returns the request body or null if this request doesn't have a body.
|
Response |
getResponse()
Returns the engine's response.
|
Route |
getRoute()
Returns the route used to retrieve the response.
|
static boolean |
hasBody(Response response)
Returns true if the response must have a (possibly 0-length) body.
|
boolean |
hasResponse() |
static String |
hostHeader(URL url) |
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(Headers headers) |
HttpEngine |
recover(IOException e) |
HttpEngine |
recover(IOException e,
okio.Sink requestBodyOut)
Report and attempt to recover from
e . |
void |
releaseConnection()
Configure the socket connection to be either pooled or closed when it is
either exhausted or closed.
|
boolean |
sameConnection(URL followUp)
Returns true if an HTTP request for
followUp can reuse the
connection used by this engine. |
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 MAX_FOLLOW_UPS
public final boolean bufferRequestBody
public HttpEngine(OkHttpClient client, Request request, boolean bufferRequestBody, boolean callerWritesRequestBody, boolean forWebSocket, Connection connection, RouteSelector routeSelector, RetryableSink requestBodyOut, Response priorResponse)
request
- the HTTP request without a body. The body must be written via the engine's
request body stream.callerWritesRequestBody
- true for the HttpURLConnection
-style interaction
model where control flow is returned to the calling application to write the request body
before the response body is readable.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.routeSelector
- the route selector used for a failed attempt immediately preceding thispublic void sendRequest() throws IOException
IOException
public void writingRequestHeaders()
public okio.Sink getRequestBody()
public okio.BufferedSink getBufferedRequestBody()
public boolean hasResponse()
public Request getRequest()
public Response getResponse()
public Connection getConnection()
public HttpEngine recover(IOException e, okio.Sink requestBodyOut)
e
. Returns a new HTTP engine
that should be used for the retry if e
is recoverable, or null if
the failure is permanent. Requests with a body can only be recovered if the
body is buffered.public HttpEngine recover(IOException e)
public Route getRoute()
public void releaseConnection() throws IOException
IOException
public void disconnect()
public Connection close()
public static boolean hasBody(Response response)
public void readResponse() throws IOException
IOException
public void receiveHeaders(Headers headers) throws IOException
IOException
public Request followUpRequest() throws IOException
IOException
public boolean sameConnection(URL followUp)
followUp
can reuse the
connection used by this engine.Copyright © 2015. All rights reserved.