/** * Adds a new header with the name and value. This may be used to add multiple headers with the * same name. Unlike {@link #addHeader(String, Object)} this does not validate the name and * value. */ public MockResponse addHeaderLenient(String name, Object value) { Internal.instance.addLenient(headers, name, String.valueOf(value)); return this; }
/** * Configures the supplied {@link SSLSocket} to connect to the specified host using an appropriate * {@link ConnectionSpec}. Returns the chosen {@link ConnectionSpec}, never {@code null}. * * @throws IOException if the socket does not support any of the TLS modes available */ public ConnectionSpec configureSecureSocket(SSLSocket sslSocket) throws IOException { ConnectionSpec tlsConfiguration = null; for (int i = nextModeIndex, size = connectionSpecs.size(); i < size; i++) { ConnectionSpec connectionSpec = connectionSpecs.get(i); if (connectionSpec.isCompatible(sslSocket)) { tlsConfiguration = connectionSpec; nextModeIndex = i + 1; break; } } if (tlsConfiguration == null) { // This may be the first time a connection has been attempted and the socket does not support // any the required protocols, or it may be a retry (but this socket supports fewer // protocols than was suggested by a prior socket). throw new UnknownServiceException( "Unable to find acceptable protocols. isFallback=" + isFallback + ", modes=" + connectionSpecs + ", supported protocols=" + Arrays.toString(sslSocket.getEnabledProtocols())); } isFallbackPossible = isFallbackPossible(sslSocket); Internal.instance.apply(tlsConfiguration, sslSocket, isFallback); return tlsConfiguration; }
if (connection.allocations.isEmpty()) { connection.idleAtNanos = System.nanoTime(); if (Internal.instance.connectionBecameIdle(connectionPool, connection)) { socket = connection.socket();
Internal.instance.acquire(connectionPool, address, this, null); if (connection != null) { foundPooledConnection = true; for (int i = 0, size = routes.size(); i < size; i++) { Route route = routes.get(i); Internal.instance.acquire(connectionPool, address, this, route); if (connection != null) { foundPooledConnection = true; Internal.instance.put(connectionPool, result); socket = Internal.instance.deduplicate(connectionPool, address, this); result = connection;
Internal.instance.get(connectionPool, address, this, null); if (connection != null) { foundPooledConnection = true; for (int i = 0, size = routes.size(); i < size; i++) { Route route = routes.get(i); Internal.instance.get(connectionPool, address, this, route); if (connection != null) { foundPooledConnection = true; Internal.instance.put(connectionPool, result); socket = Internal.instance.deduplicate(connectionPool, address, this); result = connection;
private RouteDatabase routeDatabase() { return Internal.instance.routeDatabase(connectionPool); }
@Override public Response.Builder readResponseHeaders(boolean expectContinue) throws IOException { Headers headers = stream.takeHeaders(); Response.Builder responseBuilder = readHttp2HeadersList(headers, protocol); if (expectContinue && Internal.instance.code(responseBuilder) == HTTP_CONTINUE) { return null; } return responseBuilder; }
if (!Internal.instance.equalsNonHost(this.route.address(), address)) return false;
Internal.instance.get(connectionPool, address, this, null); if (connection != null) { foundPooledConnection = true; Internal.instance.get(connectionPool, address, this, route); if (connection != null) { foundPooledConnection = true; Internal.instance.put(connectionPool, result); socket = Internal.instance.deduplicate(connectionPool, address, this); result = connection;
private RouteDatabase routeDatabase() { return Internal.instance.routeDatabase(connectionPool); }
Internal.instance.acquire(connectionPool, address, this, null); if (connection != null) { foundPooledConnection = true; for (int i = 0, size = routes.size(); i < size; i++) { Route route = routes.get(i); Internal.instance.acquire(connectionPool, address, this, route); if (connection != null) { foundPooledConnection = true; Internal.instance.put(connectionPool, result); socket = Internal.instance.deduplicate(connectionPool, address, this); result = connection;
@Override public Response.Builder readResponseHeaders(boolean expectContinue) throws IOException { Headers headers = stream.takeHeaders(); Response.Builder responseBuilder = readHttp2HeadersList(headers, protocol); if (expectContinue && Internal.instance.code(responseBuilder) == HTTP_CONTINUE) { return null; } return responseBuilder; }
if (!Internal.instance.equalsNonHost(this.route.address(), address)) return false;
/** * Returns headers for the header names and values in the {@link Map}. */ private static Headers createHeaders(Map<String, List<String>> headers) { Headers.Builder builder = new Headers.Builder(); for (Map.Entry<String, List<String>> header : headers.entrySet()) { if (header.getKey() == null || header.getValue() == null) { continue; } String name = header.getKey().trim(); for (String value : header.getValue()) { String trimmedValue = value.trim(); Internal.instance.addLenient(builder, name, trimmedValue); } } return builder.build(); }
private RouteDatabase routeDatabase() { return Internal.instance.routeDatabase(connectionPool); }
/** * Configures the supplied {@link SSLSocket} to connect to the specified host using an appropriate * {@link ConnectionSpec}. Returns the chosen {@link ConnectionSpec}, never {@code null}. * * @throws IOException if the socket does not support any of the TLS modes available */ public ConnectionSpec configureSecureSocket(SSLSocket sslSocket) throws IOException { ConnectionSpec tlsConfiguration = null; for (int i = nextModeIndex, size = connectionSpecs.size(); i < size; i++) { ConnectionSpec connectionSpec = connectionSpecs.get(i); if (connectionSpec.isCompatible(sslSocket)) { tlsConfiguration = connectionSpec; nextModeIndex = i + 1; break; } } if (tlsConfiguration == null) { // This may be the first time a connection has been attempted and the socket does not support // any the required protocols, or it may be a retry (but this socket supports fewer // protocols than was suggested by a prior socket). throw new UnknownServiceException( "Unable to find acceptable protocols. isFallback=" + isFallback + ", modes=" + connectionSpecs + ", supported protocols=" + Arrays.toString(sslSocket.getEnabledProtocols())); } isFallbackPossible = isFallbackPossible(sslSocket); Internal.instance.apply(tlsConfiguration, sslSocket, isFallback); return tlsConfiguration; }
if (connection.allocations.isEmpty()) { connection.idleAtNanos = System.nanoTime(); if (Internal.instance.connectionBecameIdle(connectionPool, connection)) { socket = connection.socket();