/** * Cause the socket connection to be released to the connection pool when * it is no longer needed. If it is already unneeded, it will be pooled * immediately. Otherwise the connection is held so that redirects can be * handled by the same connection. */ public final void automaticallyReleaseConnectionToPool() { automaticallyReleaseConnectionToPool = true; if (connection != null && connectionReleased) { client.getConnectionPool().recycle(connection); connection = null; } }
public HttpsEngine(OkHttpClient client, Policy policy, String method, RawHeaders requestHeaders, Connection connection, RetryableOutputStream requestBody) throws IOException { super(client, policy, method, requestHeaders, connection, requestBody); this.sslSocket = connection != null ? (SSLSocket) connection.getSocket() : null; }
@Override protected URLConnection openConnection(URL url) throws IOException { return newOkHttpClient(null /* proxy */).open(url); }
protected OkHttpClient newOkHttpClient(Proxy proxy) { OkHttpClient client = new OkHttpClient(); client.setFollowProtocolRedirects(false); if (proxy != null) { client.setProxy(proxy); } return client; } }
/** * 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); }
/** * Called after a socket connection has been created or retrieved from the * pool. Subclasses use this hook to get a reference to the TLS data. */ protected void connected(Connection connection) { policy.setSelectedProxy(connection.getRoute().getProxy()); connected = true; }
/** * Schedules {@code request} to be executed. */ public void enqueue(Request request, Response.Receiver responseReceiver) { // Create the HttpURLConnection immediately so the enqueued job gets the current settings of // this client. Otherwise changes to this client (socket factory, redirect policy, etc.) may // incorrectly be reflected in the request when it is dispatched later. dispatcher.enqueue(open(request.url()), request, responseReceiver); }
/** Returns total number of spdy connections in the pool. */ public synchronized int getSpdyConnectionCount() { int total = 0; for (Connection connection : connections) { if (connection.isSpdy()) total++; } return total; }
/** Resets {@link #nextTlsMode} to the first option. */ private void resetNextTlsMode() { nextTlsMode = (address.getSslSocketFactory() != null) ? TLS_MODE_MODERN : TLS_MODE_COMPATIBLE; }
public Failure build() { return new Failure(this); } }
protected OkHttpClient newOkHttpClient(Proxy proxy) { OkHttpClient client = new OkHttpClient(); client.setFollowProtocolRedirects(false); if (proxy != null) { client.setProxy(proxy); } return client; } }
/** * 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); }
@Override protected URLConnection openConnection(URL url) throws IOException { return newOkHttpClient(null /* proxy */).open(url); }
/** * Cause the socket connection to be released to the connection pool when * it is no longer needed. If it is already unneeded, it will be pooled * immediately. Otherwise the connection is held so that redirects can be * handled by the same connection. */ public final void automaticallyReleaseConnectionToPool() { automaticallyReleaseConnectionToPool = true; if (connection != null && connectionReleased) { client.getConnectionPool().recycle(connection); connection = null; } }
/** Returns total number of http connections in the pool. */ public synchronized int getHttpConnectionCount() { int total = 0; for (Connection connection : connections) { if (!connection.isSpdy()) total++; } return total; }
public HttpsEngine(OkHttpClient client, Policy policy, String method, RawHeaders requestHeaders, Connection connection, RetryableOutputStream requestBody) throws IOException { super(client, policy, method, requestHeaders, connection, requestBody); this.sslSocket = connection != null ? (SSLSocket) connection.getSocket() : null; }
@Override protected URLConnection openConnection(URL url, Proxy proxy) throws IOException { if (url == null || proxy == null) { throw new IllegalArgumentException("url == null || proxy == null"); } return newOkHttpClient(proxy).open(url); }
/** Returns total number of spdy connections in the pool. */ public synchronized int getSpdyConnectionCount() { int total = 0; for (Connection connection : connections) { if (connection.isSpdy()) total++; } return total; }
@Override protected URLConnection openConnection(URL url, Proxy proxy) throws IOException { if (url == null || proxy == null) { throw new IllegalArgumentException("url == null || proxy == null"); } return newOkHttpClient(proxy).open(url); }
/** Returns total number of http connections in the pool. */ public synchronized int getHttpConnectionCount() { int total = 0; for (Connection connection : connections) { if (!connection.isSpdy()) total++; } return total; }