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
|
| 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 |
getBufferedRequestBody()
|
Connection |
getConnection()
|
Request |
getRequest()
|
okio |
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
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
|
HttpEngine |
recover(IOException
|
HttpEngine |
recover(IOException
Report and attempt to recover from a failure to communicate with a server.
|
void |
releaseStreamAllocation()
Configure the socket connection to be either pooled or closed when it is either exhausted or closed.
|
boolean |
sameConnection(HttpUrl
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 StreamAllocationstreamAllocation
public final boolean bufferRequestBody
public HttpEngine(OkHttpClientclient, 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(java.io.IOException, okio.Sink).
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 RequestgetRequest()
public ResponsegetResponse()
public ConnectiongetConnection()
public HttpEnginerecover(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 HttpEnginerecover(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 StreamAllocationclose()
public static boolean hasBody(Responseresponse)
public void readResponse()
throws IOException
IOException
public void receiveHeaders(Headersheaders) throws IOException
IOException
public RequestfollowUpRequest() throws IOException
IOException
public boolean sameConnection(HttpUrlfollowUp)
followUp can reuse the connection used by this engine.