public final class RetryAndFollowUpInterceptor extends java.lang.Object implements Interceptor
IOException
if the call was canceled.Interceptor.Chain
Modifier and Type | Field and Description |
---|---|
private java.lang.Object |
callStackTrace |
private boolean |
canceled |
private OkHttpClient |
client |
private boolean |
forWebSocket |
private 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.
|
private StreamAllocation |
streamAllocation |
Constructor and Description |
---|
RetryAndFollowUpInterceptor(OkHttpClient client,
boolean forWebSocket) |
Modifier and Type | Method and Description |
---|---|
void |
cancel()
Immediately closes the socket connection if it's currently held.
|
private Address |
createAddress(HttpUrl url) |
private Request |
followUpRequest(Response userResponse,
Route route)
Figures out the HTTP request to make in response to receiving
userResponse . |
Response |
intercept(Interceptor.Chain chain) |
boolean |
isCanceled() |
private boolean |
isRecoverable(java.io.IOException e,
boolean requestSendStarted) |
private boolean |
recover(java.io.IOException e,
StreamAllocation streamAllocation,
boolean requestSendStarted,
Request userRequest)
Report and attempt to recover from a failure to communicate with a server.
|
private int |
retryAfter(Response userResponse,
int defaultDelay) |
private boolean |
sameConnection(Response response,
HttpUrl followUp)
Returns true if an HTTP request for
followUp can reuse the connection used by this
engine. |
void |
setCallStackTrace(java.lang.Object callStackTrace) |
StreamAllocation |
streamAllocation() |
private static final int MAX_FOLLOW_UPS
private final OkHttpClient client
private final boolean forWebSocket
private volatile StreamAllocation streamAllocation
private java.lang.Object callStackTrace
private volatile boolean canceled
public RetryAndFollowUpInterceptor(OkHttpClient client, boolean forWebSocket)
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 boolean isCanceled()
public void setCallStackTrace(java.lang.Object callStackTrace)
public StreamAllocation streamAllocation()
public Response intercept(Interceptor.Chain chain) throws java.io.IOException
intercept
in interface Interceptor
java.io.IOException
private boolean recover(java.io.IOException e, StreamAllocation streamAllocation, boolean requestSendStarted, Request userRequest)
e
is recoverable, or false if the failure is permanent. Requests with a body can only
be recovered if the body is buffered or if the failure occurred before the request has been
sent.private boolean isRecoverable(java.io.IOException e, boolean requestSendStarted)
private Request followUpRequest(Response userResponse, Route route) throws java.io.IOException
userResponse
. This will
either add authentication headers, follow redirects or handle a client request timeout. If a
follow-up is either unnecessary or not applicable, this returns null.java.io.IOException
private int retryAfter(Response userResponse, int defaultDelay)