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.
|
StreamAllocation |
streamAllocation |
Constructor and Description |
---|
HttpEngine(OkHttpClient client,
Request request,
boolean bufferRequestBody,
boolean callerWritesRequestBody,
boolean forWebSocket,
StreamAllocation streamAllocation,
RetryableSink requestBodyOut,
Response priorResponse) |
Modifier and Type | Method and Description |
---|---|
void |
cancel()
Immediately closes the socket connection if it's currently held by this engine.
|
StreamAllocation |
close()
Release any resources 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.
|
static boolean |
hasBody(Response response)
Returns true if the response must have a (possibly 0-length) body.
|
boolean |
hasResponse() |
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 a failure to communicate with a server.
|
HttpEngine |
recover(RouteException e)
Attempt to recover from failure to connect via a route.
|
void |
releaseStreamAllocation()
Configure the socket connection to be either pooled or closed when it is
either exhausted or closed.
|
boolean |
sameConnection(HttpUrl 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 StreamAllocation streamAllocation
public final boolean bufferRequestBody
public HttpEngine(OkHttpClient client, Request request, boolean bufferRequestBody, boolean callerWritesRequestBody, boolean forWebSocket, StreamAllocation streamAllocation, 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.public void sendRequest() throws RequestException, RouteException, IOException
RequestException
- if there was a problem with request setup. Unrecoverable.RouteException
- if the was a problem during connection via a specific route. Sometimes
recoverable. See recover(RouteException)
.IOException
- if there was a problem while making a request. Sometimes recoverable. See
recover(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(RouteException e)
public HttpEngine recover(IOException e, okio.Sink requestBodyOut)
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 void releaseStreamAllocation() throws IOException
IOException
public void cancel()
This method is safe to be called concurrently, but provides limited guarantees. If a transport layer connection has been established (such as a HTTP/2 stream) that is terminated. Otherwise if a socket connection is being established, that is terminated.
public StreamAllocation 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(HttpUrl followUp)
followUp
can reuse the
connection used by this engine.Copyright © 2016. All rights reserved.