Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename ConnectionConfiguration to ConnectionSpec. #1128

Merged
merged 1 commit into from
Nov 5, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ _2014-11-04_
* **TLS configuration updated.** OkHttp now explicitly enables TLSv1.2,
TLSv1.1 and TLSv1.0 where they are supported. It will continue to perform
only one fallback, to SSLv3. Applications can now configure this with the
`ConnectionConfiguration` class.
`ConnectionSpec` class.

To disable TLS fallback:

```
client.setConnectionConfigurations(Arrays.asList(
ConnectionConfiguration.MODERN_TLS, ConnectionConfiguration.CLEARTEXT));
client.setConnectionSpecs(Arrays.asList(
ConnectionSpec.MODERN_TLS, ConnectionSpec.CLEARTEXT));
```

To disable cleartext connections, permitting `https` URLs only:

```
client.setConnectionConfigurations(Arrays.asList(
ConnectionConfiguration.MODERN_TLS, ConnectionConfiguration.COMPATIBLE_TLS));
client.setConnectionSpecs(Arrays.asList(
ConnectionSpec.MODERN_TLS, ConnectionSpec.COMPATIBLE_TLS));
```

* **New cipher suites.** Please confirm that your webservers are reachable
Expand Down
9 changes: 4 additions & 5 deletions okhttp-tests/src/test/java/com/squareup/okhttp/CallTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -644,8 +644,7 @@ public final class CallTest {
}

@Test public void noRecoveryFromTlsHandshakeFailureWhenTlsFallbackIsDisabled() throws Exception {
client.setConnectionConfigurations(Arrays.asList(
ConnectionConfiguration.MODERN_TLS, ConnectionConfiguration.CLEARTEXT));
client.setConnectionSpecs(Arrays.asList(ConnectionSpec.MODERN_TLS, ConnectionSpec.CLEARTEXT));

server.useHttps(sslContext.getSocketFactory(), false);
server.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.FAIL_HANDSHAKE));
Expand All @@ -665,8 +664,8 @@ public final class CallTest {

@Test public void cleartextCallsFailWhenCleartextIsDisabled() throws Exception {
// Configure the client with only TLS configurations. No cleartext!
client.setConnectionConfigurations(Arrays.asList(
ConnectionConfiguration.MODERN_TLS, ConnectionConfiguration.COMPATIBLE_TLS));
client.setConnectionSpecs(Arrays.asList(
ConnectionSpec.MODERN_TLS, ConnectionSpec.COMPATIBLE_TLS));

server.enqueue(new MockResponse());
server.play();
Expand All @@ -676,7 +675,7 @@ public final class CallTest {
client.newCall(request).execute();
fail();
} catch (SocketException expected) {
assertTrue(expected.getMessage().contains("exhausted connection configurations"));
assertTrue(expected.getMessage().contains("exhausted connection specs"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,28 +73,28 @@ private void setUp(int poolSize) throws Exception {
httpServer = new MockWebServer();
spdyServer.useHttps(sslContext.getSocketFactory(), false);

List<ConnectionConfiguration> connectionConfigurations = Util.immutableList(
ConnectionConfiguration.MODERN_TLS, ConnectionConfiguration.CLEARTEXT);
List<ConnectionSpec> connectionSpecs = Util.immutableList(
ConnectionSpec.MODERN_TLS, ConnectionSpec.CLEARTEXT);

httpServer.play();
httpAddress = new Address(httpServer.getHostName(), httpServer.getPort(), socketFactory, null,
null, null, AuthenticatorAdapter.INSTANCE, null,
Util.immutableList(Protocol.SPDY_3, Protocol.HTTP_1_1), connectionConfigurations);
Util.immutableList(Protocol.SPDY_3, Protocol.HTTP_1_1), connectionSpecs);
httpSocketAddress = new InetSocketAddress(InetAddress.getByName(httpServer.getHostName()),
httpServer.getPort());

spdyServer.play();
spdyAddress = new Address(spdyServer.getHostName(), spdyServer.getPort(), socketFactory,
sslContext.getSocketFactory(), new RecordingHostnameVerifier(), CertificatePinner.DEFAULT,
AuthenticatorAdapter.INSTANCE, null,
Util.immutableList(Protocol.SPDY_3, Protocol.HTTP_1_1), connectionConfigurations);
Util.immutableList(Protocol.SPDY_3, Protocol.HTTP_1_1), connectionSpecs);
spdySocketAddress = new InetSocketAddress(InetAddress.getByName(spdyServer.getHostName()),
spdyServer.getPort());

Route httpRoute = new Route(httpAddress, Proxy.NO_PROXY, httpSocketAddress,
ConnectionConfiguration.CLEARTEXT);
ConnectionSpec.CLEARTEXT);
Route spdyRoute = new Route(spdyAddress, Proxy.NO_PROXY, spdySocketAddress,
ConnectionConfiguration.MODERN_TLS);
ConnectionSpec.MODERN_TLS);
pool = new ConnectionPool(poolSize, KEEP_ALIVE_DURATION_MS);
httpA = new Connection(pool, httpRoute);
httpA.connect(200, 200, 200, null);
Expand Down Expand Up @@ -140,7 +140,7 @@ private void resetWithPoolSize(int poolSize) throws Exception {
assertNull(connection);

connection = new Connection(pool, new Route(httpAddress, Proxy.NO_PROXY, httpSocketAddress,
ConnectionConfiguration.CLEARTEXT));
ConnectionSpec.CLEARTEXT));
connection.connect(200, 200, 200, null);
connection.setOwner(owner);
assertEquals(0, pool.getConnectionCount());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import com.squareup.okhttp.Address;
import com.squareup.okhttp.Authenticator;
import com.squareup.okhttp.Connection;
import com.squareup.okhttp.ConnectionConfiguration;
import com.squareup.okhttp.ConnectionSpec;
import com.squareup.okhttp.ConnectionPool;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Protocol;
Expand Down Expand Up @@ -53,10 +53,10 @@
import static org.junit.Assert.fail;

public final class RouteSelectorTest {
public final List<ConnectionConfiguration> connectionConfigurations = Util.immutableList(
ConnectionConfiguration.MODERN_TLS,
ConnectionConfiguration.COMPATIBLE_TLS,
ConnectionConfiguration.CLEARTEXT);
public final List<ConnectionSpec> connectionSpecs = Util.immutableList(
ConnectionSpec.MODERN_TLS,
ConnectionSpec.COMPATIBLE_TLS,
ConnectionSpec.CLEARTEXT);

private static final int proxyAPort = 1001;
private static final String proxyAHost = "proxyA";
Expand Down Expand Up @@ -94,7 +94,7 @@ public final class RouteSelectorTest {
.setSslSocketFactory(sslSocketFactory)
.setHostnameVerifier(hostnameVerifier)
.setProtocols(protocols)
.setConnectionConfigurations(connectionConfigurations)
.setConnectionSpecs(connectionSpecs)
.setConnectionPool(ConnectionPool.getDefault());
Internal.instance.setNetwork(client, dns);

Expand All @@ -115,7 +115,7 @@ public final class RouteSelectorTest {
assertTrue(routeSelector.hasNext());
dns.inetAddresses = makeFakeAddresses(255, 1);
assertConnection(routeSelector.nextUnconnected(), address, NO_PROXY, dns.inetAddresses[0],
uriPort, ConnectionConfiguration.CLEARTEXT);
uriPort, ConnectionSpec.CLEARTEXT);
dns.assertRequests(uriHost);

assertFalse(routeSelector.hasNext());
Expand All @@ -136,7 +136,7 @@ public final class RouteSelectorTest {
routeDatabase.failed(connection.getRoute());
routeSelector = RouteSelector.get(httpRequest, client);
assertConnection(routeSelector.nextUnconnected(), address, NO_PROXY, dns.inetAddresses[0],
uriPort, ConnectionConfiguration.CLEARTEXT);
uriPort, ConnectionSpec.CLEARTEXT);
assertFalse(routeSelector.hasNext());
try {
routeSelector.nextUnconnected();
Expand All @@ -147,16 +147,16 @@ public final class RouteSelectorTest {

@Test public void explicitProxyTriesThatProxysAddressesOnly() throws Exception {
Address address = new Address(uriHost, uriPort, socketFactory, null, null, null, authenticator,
proxyA, protocols, connectionConfigurations);
proxyA, protocols, connectionSpecs);
client.setProxy(proxyA);
RouteSelector routeSelector = RouteSelector.get(httpRequest, client);

assertTrue(routeSelector.hasNext());
dns.inetAddresses = makeFakeAddresses(255, 2);
assertConnection(routeSelector.nextUnconnected(), address, proxyA, dns.inetAddresses[0],
proxyAPort, ConnectionConfiguration.CLEARTEXT);
proxyAPort, ConnectionSpec.CLEARTEXT);
assertConnection(routeSelector.nextUnconnected(), address, proxyA, dns.inetAddresses[1],
proxyAPort, ConnectionConfiguration.CLEARTEXT);
proxyAPort, ConnectionSpec.CLEARTEXT);

assertFalse(routeSelector.hasNext());
dns.assertRequests(proxyAHost);
Expand All @@ -165,16 +165,16 @@ public final class RouteSelectorTest {

@Test public void explicitDirectProxy() throws Exception {
Address address = new Address(uriHost, uriPort, socketFactory, null, null, null, authenticator,
NO_PROXY, protocols, connectionConfigurations);
NO_PROXY, protocols, connectionSpecs);
client.setProxy(NO_PROXY);
RouteSelector routeSelector = RouteSelector.get(httpRequest, client);

assertTrue(routeSelector.hasNext());
dns.inetAddresses = makeFakeAddresses(255, 2);
assertConnection(routeSelector.nextUnconnected(), address, NO_PROXY, dns.inetAddresses[0],
uriPort, ConnectionConfiguration.CLEARTEXT);
uriPort, ConnectionSpec.CLEARTEXT);
assertConnection(routeSelector.nextUnconnected(), address, NO_PROXY, dns.inetAddresses[1],
uriPort, ConnectionConfiguration.CLEARTEXT);
uriPort, ConnectionSpec.CLEARTEXT);

assertFalse(routeSelector.hasNext());
dns.assertRequests(uriHost);
Expand All @@ -191,7 +191,7 @@ public final class RouteSelectorTest {
assertTrue(routeSelector.hasNext());
dns.inetAddresses = makeFakeAddresses(255, 1);
assertConnection(routeSelector.nextUnconnected(), address, NO_PROXY, dns.inetAddresses[0],
uriPort, ConnectionConfiguration.CLEARTEXT);
uriPort, ConnectionSpec.CLEARTEXT);
dns.assertRequests(uriHost);

assertFalse(routeSelector.hasNext());
Expand All @@ -204,9 +204,9 @@ public final class RouteSelectorTest {
assertTrue(routeSelector.hasNext());
dns.inetAddresses = makeFakeAddresses(255, 2);
assertConnection(routeSelector.nextUnconnected(), address, NO_PROXY, dns.inetAddresses[0],
uriPort, ConnectionConfiguration.CLEARTEXT);
uriPort, ConnectionSpec.CLEARTEXT);
assertConnection(routeSelector.nextUnconnected(), address, NO_PROXY, dns.inetAddresses[1],
uriPort, ConnectionConfiguration.CLEARTEXT);
uriPort, ConnectionSpec.CLEARTEXT);

assertFalse(routeSelector.hasNext());
dns.assertRequests(uriHost);
Expand All @@ -225,23 +225,23 @@ public final class RouteSelectorTest {
assertTrue(routeSelector.hasNext());
dns.inetAddresses = makeFakeAddresses(255, 2);
assertConnection(routeSelector.nextUnconnected(), address, proxyA, dns.inetAddresses[0], proxyAPort,
ConnectionConfiguration.CLEARTEXT);
ConnectionSpec.CLEARTEXT);
assertConnection(routeSelector.nextUnconnected(), address, proxyA, dns.inetAddresses[1], proxyAPort,
ConnectionConfiguration.CLEARTEXT);
ConnectionSpec.CLEARTEXT);
dns.assertRequests(proxyAHost);

// Next try the IP address of the second proxy.
assertTrue(routeSelector.hasNext());
dns.inetAddresses = makeFakeAddresses(254, 1);
assertConnection(routeSelector.nextUnconnected(), address, proxyB, dns.inetAddresses[0], proxyBPort,
ConnectionConfiguration.CLEARTEXT);
ConnectionSpec.CLEARTEXT);
dns.assertRequests(proxyBHost);

// Finally try the only IP address of the origin server.
assertTrue(routeSelector.hasNext());
dns.inetAddresses = makeFakeAddresses(253, 1);
assertConnection(routeSelector.nextUnconnected(), address, NO_PROXY, dns.inetAddresses[0], uriPort,
ConnectionConfiguration.CLEARTEXT);
ConnectionSpec.CLEARTEXT);
dns.assertRequests(uriHost);

assertFalse(routeSelector.hasNext());
Expand All @@ -258,7 +258,7 @@ public final class RouteSelectorTest {
assertTrue(routeSelector.hasNext());
dns.inetAddresses = makeFakeAddresses(255, 1);
assertConnection(routeSelector.nextUnconnected(), address, NO_PROXY, dns.inetAddresses[0], uriPort,
ConnectionConfiguration.CLEARTEXT);
ConnectionSpec.CLEARTEXT);
dns.assertRequests(uriHost);

assertFalse(routeSelector.hasNext());
Expand All @@ -276,7 +276,7 @@ public final class RouteSelectorTest {
assertTrue(routeSelector.hasNext());
dns.inetAddresses = makeFakeAddresses(255, 1);
assertConnection(routeSelector.nextUnconnected(), address, proxyA, dns.inetAddresses[0],
proxyAPort, ConnectionConfiguration.CLEARTEXT);
proxyAPort, ConnectionSpec.CLEARTEXT);
dns.assertRequests(proxyAHost);

assertTrue(routeSelector.hasNext());
Expand All @@ -291,13 +291,13 @@ public final class RouteSelectorTest {
assertTrue(routeSelector.hasNext());
dns.inetAddresses = makeFakeAddresses(255, 1);
assertConnection(routeSelector.nextUnconnected(), address, proxyA, dns.inetAddresses[0],
proxyAPort, ConnectionConfiguration.CLEARTEXT);
proxyAPort, ConnectionSpec.CLEARTEXT);
dns.assertRequests(proxyAHost);

assertTrue(routeSelector.hasNext());
dns.inetAddresses = makeFakeAddresses(254, 1);
assertConnection(routeSelector.nextUnconnected(), address, NO_PROXY, dns.inetAddresses[0],
uriPort, ConnectionConfiguration.CLEARTEXT);
uriPort, ConnectionSpec.CLEARTEXT);
dns.assertRequests(uriHost);

assertFalse(routeSelector.hasNext());
Expand Down Expand Up @@ -328,46 +328,46 @@ public final class RouteSelectorTest {

@Test public void multipleProxiesMultipleInetAddressesMultipleConfigurations() throws Exception {
Address address = new Address(uriHost, uriPort, socketFactory, sslSocketFactory,
hostnameVerifier, null, authenticator, null, protocols, connectionConfigurations);
hostnameVerifier, null, authenticator, null, protocols, connectionSpecs);
proxySelector.proxies.add(proxyA);
proxySelector.proxies.add(proxyB);
RouteSelector routeSelector = RouteSelector.get(httpsRequest, client);

// Proxy A
dns.inetAddresses = makeFakeAddresses(255, 2);
assertConnection(routeSelector.nextUnconnected(), address, proxyA, dns.inetAddresses[0],
proxyAPort, ConnectionConfiguration.MODERN_TLS);
proxyAPort, ConnectionSpec.MODERN_TLS);
dns.assertRequests(proxyAHost);
assertConnection(routeSelector.nextUnconnected(), address, proxyA, dns.inetAddresses[0],
proxyAPort, ConnectionConfiguration.COMPATIBLE_TLS);
proxyAPort, ConnectionSpec.COMPATIBLE_TLS);
assertConnection(routeSelector.nextUnconnected(), address, proxyA, dns.inetAddresses[1],
proxyAPort, ConnectionConfiguration.MODERN_TLS);
proxyAPort, ConnectionSpec.MODERN_TLS);
assertConnection(routeSelector.nextUnconnected(), address, proxyA, dns.inetAddresses[1],
proxyAPort, ConnectionConfiguration.COMPATIBLE_TLS);
proxyAPort, ConnectionSpec.COMPATIBLE_TLS);

// Proxy B
dns.inetAddresses = makeFakeAddresses(254, 2);
assertConnection(routeSelector.nextUnconnected(), address, proxyB, dns.inetAddresses[0],
proxyBPort, ConnectionConfiguration.MODERN_TLS);
proxyBPort, ConnectionSpec.MODERN_TLS);
dns.assertRequests(proxyBHost);
assertConnection(routeSelector.nextUnconnected(), address, proxyB, dns.inetAddresses[0],
proxyBPort, ConnectionConfiguration.COMPATIBLE_TLS);
proxyBPort, ConnectionSpec.COMPATIBLE_TLS);
assertConnection(routeSelector.nextUnconnected(), address, proxyB, dns.inetAddresses[1],
proxyBPort, ConnectionConfiguration.MODERN_TLS);
proxyBPort, ConnectionSpec.MODERN_TLS);
assertConnection(routeSelector.nextUnconnected(), address, proxyB, dns.inetAddresses[1],
proxyBPort, ConnectionConfiguration.COMPATIBLE_TLS);
proxyBPort, ConnectionSpec.COMPATIBLE_TLS);

// Origin
dns.inetAddresses = makeFakeAddresses(253, 2);
assertConnection(routeSelector.nextUnconnected(), address, NO_PROXY, dns.inetAddresses[0],
uriPort, ConnectionConfiguration.MODERN_TLS);
uriPort, ConnectionSpec.MODERN_TLS);
dns.assertRequests(uriHost);
assertConnection(routeSelector.nextUnconnected(), address, NO_PROXY, dns.inetAddresses[0],
uriPort, ConnectionConfiguration.COMPATIBLE_TLS);
uriPort, ConnectionSpec.COMPATIBLE_TLS);
assertConnection(routeSelector.nextUnconnected(), address, NO_PROXY, dns.inetAddresses[1],
uriPort, ConnectionConfiguration.MODERN_TLS);
uriPort, ConnectionSpec.MODERN_TLS);
assertConnection(routeSelector.nextUnconnected(), address, NO_PROXY, dns.inetAddresses[1],
uriPort, ConnectionConfiguration.COMPATIBLE_TLS);
uriPort, ConnectionSpec.COMPATIBLE_TLS);

assertFalse(routeSelector.hasNext());
}
Expand Down Expand Up @@ -402,18 +402,18 @@ public final class RouteSelectorTest {
}

private void assertConnection(Connection connection, Address address, Proxy proxy,
InetAddress socketAddress, int socketPort, ConnectionConfiguration connectionConfiguration) {
InetAddress socketAddress, int socketPort, ConnectionSpec connectionSpec) {
assertEquals(address, connection.getRoute().getAddress());
assertEquals(proxy, connection.getRoute().getProxy());
assertEquals(socketAddress, connection.getRoute().getSocketAddress().getAddress());
assertEquals(socketPort, connection.getRoute().getSocketAddress().getPort());
assertEquals(connectionConfiguration, connection.getRoute().getConnectionConfiguration());
assertEquals(connectionSpec, connection.getRoute().getConnectionSpec());
}

/** Returns an address that's without an SSL socket factory or hostname verifier. */
private Address httpAddress() {
return new Address(uriHost, uriPort, socketFactory, null, null, null, authenticator, null,
protocols, connectionConfigurations);
protocols, connectionSpecs);
}

private static InetAddress[] makeFakeAddresses(int prefix, int count) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import com.squareup.okhttp.Cache;
import com.squareup.okhttp.Challenge;
import com.squareup.okhttp.ConnectionConfiguration;
import com.squareup.okhttp.ConnectionSpec;
import com.squareup.okhttp.ConnectionPool;
import com.squareup.okhttp.Credentials;
import com.squareup.okhttp.OkHttpClient;
Expand Down Expand Up @@ -855,8 +855,7 @@ private void testConnectViaHttpProxyToHttps(ProxyConfig proxyConfig) throws Exce
// Configure a single IP address for the host and a single configuration, so we only need one
// failure to fail permanently.
Internal.instance.setNetwork(client.client(), new SingleInetAddressNetwork());
client.client().setConnectionConfigurations(
Util.immutableList(ConnectionConfiguration.MODERN_TLS));
client.client().setConnectionSpecs(Util.immutableList(ConnectionSpec.MODERN_TLS));
server.enqueue(response);
server.play();
client.client().setProxy(server.toProxyAddress());
Expand Down
Loading