An HTTP & SPDY client for Android and Java applications with efficient connection pooling, interceptors, and modern protocol support
—
Connection pooling, SSL/TLS configuration, and connection specifications for performance optimization.
Manages HTTP/HTTPS connection reuse to reduce latency and resource usage.
public final class ConnectionPool {
public ConnectionPool(int maxIdleConnections, long keepAliveDurationMs);
public ConnectionPool(int maxIdleConnections, long keepAliveDuration, TimeUnit timeUnit);
public static ConnectionPool getDefault();
public int getIdleConnectionCount();
public int getConnectionCount();
public int getSpdyConnectionCount();
public int getMultiplexedConnectionCount();
public int getHttpConnectionCount();
public void evictAll();
}Configuration for socket connections including TLS versions and cipher suites.
public final class ConnectionSpec {
public static final ConnectionSpec MODERN_TLS;
public static final ConnectionSpec COMPATIBLE_TLS;
public static final ConnectionSpec CLEARTEXT;
public boolean isTls();
public List<CipherSuite> cipherSuites();
public List<TlsVersion> tlsVersions();
public boolean supportsTlsExtensions();
public boolean isCompatible(SSLSocket socket);
}Policy for executing asynchronous requests with thread pool management.
public final class Dispatcher {
public Dispatcher();
public Dispatcher(ExecutorService executorService);
public ExecutorService getExecutorService();
public void setMaxRequests(int maxRequests);
public int getMaxRequests();
public void setMaxRequestsPerHost(int maxRequestsPerHost);
public int getMaxRequestsPerHost();
public void cancel(Object tag);
public int getRunningCallCount();
public int getQueuedCallCount();
}Usage Examples:
// Custom connection pool
ConnectionPool pool = new ConnectionPool(10, 5, TimeUnit.MINUTES);
client.setConnectionPool(pool);
// Modern TLS only
List<ConnectionSpec> specs = Arrays.asList(
ConnectionSpec.MODERN_TLS,
ConnectionSpec.CLEARTEXT
);
client.setConnectionSpecs(specs);
// Custom dispatcher limits
Dispatcher dispatcher = new Dispatcher();
dispatcher.setMaxRequests(100);
dispatcher.setMaxRequestsPerHost(10);
client.setDispatcher(dispatcher);Install with Tessl CLI
npx tessl i tessl/maven-com-squareup-okhttp--okhttp