List of usage examples for com.squareup.okhttp.internal.http HttpEngine MAX_FOLLOW_UPS
int MAX_FOLLOW_UPS
To view the source code for com.squareup.okhttp.internal.http HttpEngine MAX_FOLLOW_UPS.
Click Source Link
From source file:io.apiman.gateway.platforms.servlet.connectors.ok.HttpURLConnectionImpl.java
License:Apache License
/** * Aggressively tries to get the final HTTP response, potentially making * many HTTP requests in the process in order to cope with redirects and * authentication./*w w w. j a va 2s.co m*/ */ private HttpEngine getResponse() throws IOException { initHttpEngine(); if (httpEngine.hasResponse()) { return httpEngine; } while (true) { if (!execute(true)) { continue; } Response response = httpEngine.getResponse(); Request followUp = httpEngine.followUpRequest(); if (followUp == null) { httpEngine.releaseConnection(); return httpEngine; } if (++followUpCount > HttpEngine.MAX_FOLLOW_UPS) { throw new ProtocolException("Too many follow-up requests: " + followUpCount); } // The first request was insufficient. Prepare for another... url = followUp.url(); requestHeaders = followUp.headers().newBuilder(); // Although RFC 2616 10.3.2 specifies that a HTTP_MOVED_PERM redirect // should keep the same method, Chrome, Firefox and the RI all issue GETs // when following any redirect. Sink requestBody = httpEngine.getRequestBody(); if (!followUp.method().equals(method)) { requestBody = null; } if (requestBody != null && !(requestBody instanceof RetryableSink)) { throw new HttpRetryException("Cannot retry streamed HTTP body", responseCode); } if (!httpEngine.sameConnection(followUp.url())) { httpEngine.releaseConnection(); } Connection connection = httpEngine.close(); httpEngine = newHttpEngine(followUp.method(), connection, (RetryableSink) requestBody, response); } }