private RealCall(OkHttpClient client, Request originalRequest, boolean forWebSocket) { this.client = client; this.originalRequest = originalRequest; this.forWebSocket = forWebSocket; this.retryAndFollowUpInterceptor = new RetryAndFollowUpInterceptor(client); this.timeout = new AsyncTimeout() { @Override protected void timedOut() { cancel(); } }; this.timeout.timeout(client.callTimeoutMillis(), MILLISECONDS); }
@Override public void cancel() { retryAndFollowUpInterceptor.cancel(); }
@Override public boolean isCanceled() { return retryAndFollowUpInterceptor.isCanceled(); }
/** * Report and attempt to recover from a failure to communicate with a server. Returns true if * {@code 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 recover(IOException e, StreamAllocation streamAllocation, boolean requestSendStarted, Request userRequest) { streamAllocation.streamFailed(e); // The application layer has forbidden retries. if (!client.retryOnConnectionFailure()) return false; // We can't send the request body again. if (requestSendStarted && requestIsUnrepeatable(e, userRequest)) return false; // This exception is fatal. if (!isRecoverable(e, requestSendStarted)) return false; // No more routes to attempt. if (!streamAllocation.hasMoreRoutes()) return false; // For failure recovery, use the same route selector with a new connection. return true; }
createAddress(request.url()), call, eventListener, callStackTrace); this.streamAllocation = streamAllocation; } catch (RouteException e) { if (!recover(e.getLastConnectException(), streamAllocation, false, request)) { throw e.getFirstConnectException(); if (!recover(e, streamAllocation, requestSendStarted, request)) throw e; releaseConnection = false; continue; followUp = followUpRequest(response, streamAllocation.route()); } catch (IOException e) { streamAllocation.release(true); if (!sameConnection(response, followUp.url())) { streamAllocation.release(false); streamAllocation = new StreamAllocation(client.connectionPool(), createAddress(followUp.url()), call, eventListener, callStackTrace); this.streamAllocation = streamAllocation; } else if (streamAllocation.codec() != null) {
if (!sameConnection(userResponse, url)) { requestBuilder.removeHeader("Authorization"); if (retryAfter(userResponse, 0) > 0) { return null; if (retryAfter(userResponse, Integer.MAX_VALUE) == 0) {
private void captureCallStackTrace() { Object callStackTrace = Platform.get().getStackTraceForCloseable("response.body().close()"); retryAndFollowUpInterceptor.setCallStackTrace(callStackTrace); }
/** * Report and attempt to recover from a failure to communicate with a server. Returns true if * {@code 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 recover(IOException e, boolean requestSendStarted, Request userRequest) { streamAllocation.streamFailed(e); // The application layer has forbidden retries. if (!client.retryOnConnectionFailure()) return false; // We can't send the request body again. if (requestSendStarted && userRequest.body() instanceof UnrepeatableRequestBody) return false; // This exception is fatal. if (!isRecoverable(e, requestSendStarted)) return false; // No more routes to attempt. if (!streamAllocation.hasMoreRoutes()) return false; // For failure recovery, use the same route selector with a new connection. return true; }
createAddress(request.url()), call, eventListener, callStackTrace); this.streamAllocation = streamAllocation; } catch (RouteException e) { if (!recover(e.getLastConnectException(), streamAllocation, false, request)) { throw e.getFirstConnectException(); if (!recover(e, streamAllocation, requestSendStarted, request)) throw e; releaseConnection = false; continue; followUp = followUpRequest(response, streamAllocation.route()); } catch (IOException e) { streamAllocation.release(true); if (!sameConnection(response, followUp.url())) { streamAllocation.release(false); streamAllocation = new StreamAllocation(client.connectionPool(), createAddress(followUp.url()), call, eventListener, callStackTrace); this.streamAllocation = streamAllocation; } else if (streamAllocation.codec() != null) {
if (!sameConnection(userResponse, url)) { requestBuilder.removeHeader("Authorization"); if (retryAfter(userResponse, 0) > 0) { return null; if (retryAfter(userResponse, Integer.MAX_VALUE) == 0) {
private void captureCallStackTrace() { Object callStackTrace = Platform.get().getStackTraceForCloseable("response.body().close()"); retryAndFollowUpInterceptor.setCallStackTrace(callStackTrace); }
/** * Report and attempt to recover from a failure to communicate with a server. Returns true if * {@code 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 recover(IOException e, StreamAllocation streamAllocation, boolean requestSendStarted, Request userRequest) { streamAllocation.streamFailed(e); // The application layer has forbidden retries. if (!client.retryOnConnectionFailure()) return false; // We can't send the request body again. if (requestSendStarted && requestIsUnrepeatable(e, userRequest)) return false; // This exception is fatal. if (!isRecoverable(e, requestSendStarted)) return false; // No more routes to attempt. if (!streamAllocation.hasMoreRoutes()) return false; // For failure recovery, use the same route selector with a new connection. return true; }
/** * Report and attempt to recover from a failure to communicate with a server. Returns true if * {@code 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 recover(IOException e, StreamAllocation streamAllocation, boolean requestSendStarted, Request userRequest) { streamAllocation.streamFailed(e); // The application layer has forbidden retries. if (!client.retryOnConnectionFailure()) return false; // We can't send the request body again. if (requestSendStarted && userRequest.body() instanceof UnrepeatableRequestBody) return false; // This exception is fatal. if (!isRecoverable(e, requestSendStarted)) return false; // No more routes to attempt. if (!streamAllocation.hasMoreRoutes()) return false; // For failure recovery, use the same route selector with a new connection. return true; }
EventListener eventListener = realChain.eventListener(); streamAllocation = new StreamAllocation(client.connectionPool(), createAddress(request.url()), call, eventListener, callStackTrace); } catch (RouteException e) { if (!recover(e.getLastConnectException(), false, request)) { throw e.getLastConnectException(); if (!recover(e, requestSendStarted, request)) throw e; releaseConnection = false; continue; Request followUp = followUpRequest(response); if (!sameConnection(response, followUp.url())) { streamAllocation.release(); streamAllocation = new StreamAllocation(client.connectionPool(), createAddress(followUp.url()), call, eventListener, callStackTrace); } else if (streamAllocation.codec() != null) { throw new IllegalStateException("Closing the body of " + response
if (!sameConnection(userResponse, url)) { requestBuilder.removeHeader("Authorization"); if (retryAfter(userResponse, 0) > 0) { return null; if (retryAfter(userResponse, Integer.MAX_VALUE) == 0) {
@Override public boolean isCanceled() { return retryAndFollowUpInterceptor.isCanceled(); }
private RealCall(OkHttpClient client, Request originalRequest, boolean forWebSocket) { this.client = client; this.originalRequest = originalRequest; this.forWebSocket = forWebSocket; this.retryAndFollowUpInterceptor = new RetryAndFollowUpInterceptor(client); this.timeout = new AsyncTimeout() { @Override protected void timedOut() { cancel(); } }; this.timeout.timeout(client.callTimeoutMillis(), MILLISECONDS); }
private void captureCallStackTrace() { Object callStackTrace = Platform.get().getStackTraceForCloseable("response.body().close()"); retryAndFollowUpInterceptor.setCallStackTrace(callStackTrace); }
@Override public void cancel() { retryAndFollowUpInterceptor.cancel(); }
createAddress(request.url()), call, eventListener, callStackTrace); this.streamAllocation = streamAllocation; } catch (RouteException e) { if (!recover(e.getLastConnectException(), streamAllocation, false, request)) { throw e.getFirstConnectException(); if (!recover(e, streamAllocation, requestSendStarted, request)) throw e; releaseConnection = false; continue; followUp = followUpRequest(response, streamAllocation.route()); } catch (IOException e) { streamAllocation.release(); if (!sameConnection(response, followUp.url())) { streamAllocation.release(); streamAllocation = new StreamAllocation(client.connectionPool(), createAddress(followUp.url()), call, eventListener, callStackTrace); this.streamAllocation = streamAllocation; } else if (streamAllocation.codec() != null) {