本文整理汇总了Java中com.squareup.okhttp.Connection类的典型用法代码示例。如果您正苦于以下问题:Java Connection类的具体用法?Java Connection怎么用?Java Connection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Connection类属于com.squareup.okhttp包,在下文中一共展示了Connection类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: HttpEngine
import com.squareup.okhttp.Connection; //导入依赖的package包/类
/**
* @param requestHeaders the client's supplied request headers. This class
* creates a private copy that it can mutate.
* @param connection the connection used for an intermediate response
* immediately prior to this request/response pair, such as a same-host
* redirect. This engine assumes ownership of the connection and must
* release it when it is unneeded.
*/
public HttpEngine(OkHttpClient client, Policy policy, String method, RawHeaders requestHeaders,
Connection connection, RetryableOutputStream requestBodyOut) throws IOException {
this.client = client;
this.policy = policy;
this.method = method;
this.connection = connection;
this.requestBodyOut = requestBodyOut;
try {
uri = Platform.get().toUriLenient(policy.getURL());
} catch (URISyntaxException e) {
throw new IOException(e.getMessage());
}
this.requestHeaders = new RequestHeaders(uri, new RawHeaders(requestHeaders));
}
示例2: discardStream
import com.squareup.okhttp.Connection; //导入依赖的package包/类
/**
* Discards the response body so that the connection can be reused. This
* needs to be done judiciously, since it delays the current request in
* order to speed up a potential future request that may never occur.
*
* <p>A stream may be discarded to encourage response caching (a response
* cannot be cached unless it is consumed completely) or to enable connection
* reuse.
*/
private static boolean discardStream(HttpEngine httpEngine, InputStream responseBodyIn) {
Connection connection = httpEngine.connection;
if (connection == null) return false;
Socket socket = connection.getSocket();
if (socket == null) return false;
try {
int socketTimeout = socket.getSoTimeout();
socket.setSoTimeout(DISCARD_STREAM_TIMEOUT_MILLIS);
try {
Util.skipAll(responseBodyIn);
return true;
} finally {
socket.setSoTimeout(socketTimeout);
}
} catch (IOException e) {
return false;
}
}
示例3: HttpEngine
import com.squareup.okhttp.Connection; //导入依赖的package包/类
public HttpEngine(OkHttpClient paramOkHttpClient, Request paramRequest, boolean paramBoolean1, boolean paramBoolean2, boolean paramBoolean3, Connection paramConnection, RouteSelector paramRouteSelector, RetryableSink paramRetryableSink, Response paramResponse)
{
this.client = paramOkHttpClient;
this.userRequest = paramRequest;
this.bufferRequestBody = paramBoolean1;
this.callerWritesRequestBody = paramBoolean2;
this.forWebSocket = paramBoolean3;
this.connection = paramConnection;
this.routeSelector = paramRouteSelector;
this.requestBodyOut = null;
this.priorResponse = paramResponse;
if (paramConnection != null)
{
Internal.instance.setOwner(paramConnection, this);
this.route = paramConnection.route;
return;
}
this.route = null;
}
示例4: discardStream
import com.squareup.okhttp.Connection; //导入依赖的package包/类
/**
* Discards the response body so that the connection can be reused. This
* needs to be done judiciously, since it delays the current request in
* order to speed up a potential future request that may never occur.
* <p/>
* <p>A stream may be discarded to encourage response caching (a response
* cannot be cached unless it is consumed completely) or to enable connection
* reuse.
*/
private static boolean discardStream(HttpEngine httpEngine, InputStream responseBodyIn) {
Connection connection = httpEngine.connection;
if (connection == null)
return false;
Socket socket = connection.getSocket();
if (socket == null)
return false;
try {
int socketTimeout = socket.getSoTimeout();
socket.setSoTimeout(DISCARD_STREAM_TIMEOUT_MILLIS);
try {
Util.skipAll(responseBodyIn);
return true;
} finally {
socket.setSoTimeout(socketTimeout);
}
} catch (IOException e) {
return false;
}
}
示例5: newHttpEngine
import com.squareup.okhttp.Connection; //导入依赖的package包/类
private HttpEngine newHttpEngine(String method, RawHeaders requestHeaders,
Connection connection, RetryableOutputStream requestBody) throws IOException {
if (url.getProtocol().equals("http")) {
return new HttpEngine(client, this, method, requestHeaders, connection, requestBody);
} else if (url.getProtocol().equals("https")) {
return new HttpsEngine(client, this, method, requestHeaders, connection, requestBody);
} else {
throw new AssertionError();
}
}
示例6: next
import com.squareup.okhttp.Connection; //导入依赖的package包/类
/**
* Returns the next route address to attempt.
*
* @throws NoSuchElementException if there are no more routes to attempt.
*/
public Connection next(String method) throws IOException {
// Always prefer pooled connections over new connections.
for (Connection pooled; (pooled = pool.get(address)) != null; ) {
if (method.equals("GET") || pooled.isReadable()) return pooled;
pooled.close();
}
// Compute the next route to attempt.
if (!hasNextTlsMode()) {
if (!hasNextInetSocketAddress()) {
if (!hasNextProxy()) {
if (!hasNextPostponed()) {
throw new NoSuchElementException();
}
return new Connection(nextPostponed());
}
lastProxy = nextProxy();
resetNextInetSocketAddress(lastProxy);
}
lastInetSocketAddress = nextInetSocketAddress();
resetNextTlsMode();
}
boolean modernTls = nextTlsMode() == TLS_MODE_MODERN;
Route route = new Route(address, lastProxy, lastInetSocketAddress, modernTls);
if (routeDatabase.shouldPostpone(route)) {
postponedRoutes.add(route);
// We will only recurse in order to skip previously failed routes. They will be
// tried last.
return next(method);
}
return new Connection(route);
}
示例7: connectFailed
import com.squareup.okhttp.Connection; //导入依赖的package包/类
/**
* Clients should invoke this method when they encounter a connectivity
* failure on a connection returned by this route selector.
*/
public void connectFailed(Connection connection, IOException failure) {
Route failedRoute = connection.getRoute();
if (failedRoute.getProxy().type() != Proxy.Type.DIRECT && proxySelector != null) {
// Tell the proxy selector when we fail to connect on a fresh connection.
proxySelector.connectFailed(uri, failedRoute.getProxy().address(), failure);
}
routeDatabase.failed(failedRoute, failure);
}