1
0
mirror of https://github.com/square/okhttp.git synced 2026-01-18 20:40:58 +03:00

Merge pull request #722 from square/jwilson_0418_even_more_protocol

Use 'Protocol' to describe framing.
This commit is contained in:
Jake Wharton
2014-04-18 20:07:20 -07:00
7 changed files with 14 additions and 47 deletions

View File

@@ -147,7 +147,7 @@ public class Main extends HelpOption implements Runnable {
private OkHttpClient createClient() {
OkHttpClient client = new OkHttpClient();
client.setFollowProtocolRedirects(followRedirects);
client.setFollowSslRedirects(followRedirects);
if (connectTimeout != DEFAULT_TIMEOUT) {
client.setConnectTimeout(connectTimeout, SECONDS);
}

View File

@@ -231,7 +231,7 @@ public final class AsyncApiTest {
}
@Test public void redirectWithRedirectsDisabled() throws Exception {
client.setFollowProtocolRedirects(false);
client.setFollowSslRedirects(false);
server.enqueue(new MockResponse()
.setResponseCode(301)
.addHeader("Location: /b")

View File

@@ -202,7 +202,7 @@ public final class SyncApiTest {
}
@Test public void redirectWithRedirectsDisabled() throws Exception {
client.setFollowProtocolRedirects(false);
client.setFollowSslRedirects(false);
server.enqueue(new MockResponse()
.setResponseCode(301)
.addHeader("Location: /b")

View File

@@ -1715,7 +1715,7 @@ public final class URLConnectionTest {
.setBody("This page has moved!"));
server.play();
client.setFollowProtocolRedirects(false);
client.setFollowSslRedirects(false);
client.setSslSocketFactory(sslContext.getSocketFactory());
client.setHostnameVerifier(new RecordingHostnameVerifier());
connection = client.open(server.getUrl("/"));
@@ -1728,7 +1728,7 @@ public final class URLConnectionTest {
.setBody("This page has moved!"));
server.play();
client.setFollowProtocolRedirects(false);
client.setFollowSslRedirects(false);
connection = client.open(server.getUrl("/"));
assertEquals("This page has moved!", readAscii(connection.getInputStream(), Integer.MAX_VALUE));
}
@@ -1746,7 +1746,7 @@ public final class URLConnectionTest {
client.setSslSocketFactory(sslContext.getSocketFactory());
client.setHostnameVerifier(new RecordingHostnameVerifier());
client.setFollowProtocolRedirects(true);
client.setFollowSslRedirects(true);
HttpsURLConnection connection = (HttpsURLConnection) client.open(server.getUrl("/"));
assertContent("This is insecure HTTP!", connection);
assertNull(connection.getCipherSuite());
@@ -1769,7 +1769,7 @@ public final class URLConnectionTest {
client.setSslSocketFactory(sslContext.getSocketFactory());
client.setHostnameVerifier(new RecordingHostnameVerifier());
client.setFollowProtocolRedirects(true);
client.setFollowSslRedirects(true);
connection = client.open(server.getUrl("/"));
assertContent("This is secure HTTPS!", connection);
assertFalse(connection instanceof HttpsURLConnection);

View File

@@ -192,7 +192,7 @@ final class Job extends NamedRunnable {
case HTTP_MOVED_TEMP:
case HTTP_SEE_OTHER:
case HTTP_TEMP_REDIRECT:
if (!client.getFollowProtocolRedirects()) {
if (!client.getFollowSslRedirects()) {
return null; // This client has is configured to not follow redirects.
}

View File

@@ -32,7 +32,6 @@ import java.net.URLConnection;
import java.net.URLStreamHandler;
import java.net.URLStreamHandlerFactory;
import java.security.GeneralSecurityException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.net.SocketFactory;
@@ -65,7 +64,7 @@ public final class OkHttpClient implements URLStreamHandlerFactory, Cloneable {
private HostnameVerifier hostnameVerifier;
private OkAuthenticator authenticator;
private ConnectionPool connectionPool;
private boolean followProtocolRedirects = true;
private boolean followSslRedirects = true;
private int connectTimeout;
private int readTimeout;
private int writeTimeout;
@@ -282,13 +281,13 @@ public final class OkHttpClient implements URLStreamHandlerFactory, Cloneable {
* <p>If unset, protocol redirects will be followed. This is different than
* the built-in {@code HttpURLConnection}'s default.
*/
public OkHttpClient setFollowProtocolRedirects(boolean followProtocolRedirects) {
this.followProtocolRedirects = followProtocolRedirects;
public OkHttpClient setFollowSslRedirects(boolean followProtocolRedirects) {
this.followSslRedirects = followProtocolRedirects;
return this;
}
public boolean getFollowProtocolRedirects() {
return followProtocolRedirects;
public boolean getFollowSslRedirects() {
return followSslRedirects;
}
public RouteDatabase getRoutesDatabase() {
@@ -309,24 +308,6 @@ public final class OkHttpClient implements URLStreamHandlerFactory, Cloneable {
return dispatcher;
}
/**
* @deprecated OkHttp 1.5 enforces an enumeration of {@link Protocol
* protocols} that can be selected. Please switch to {@link
* #setProtocols(java.util.List)}.
*/
@Deprecated
public OkHttpClient setTransports(List<String> transports) {
List<Protocol> protocols = new ArrayList<Protocol>(transports.size());
for (int i = 0, size = transports.size(); i < size; i++) {
try {
protocols.add(Protocol.get(transports.get(i)));
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
}
return setProtocols(protocols);
}
/**
* Configure the protocols used by this client to communicate with remote
* servers. By default this client will prefer the most efficient transport
@@ -367,20 +348,6 @@ public final class OkHttpClient implements URLStreamHandlerFactory, Cloneable {
return this;
}
/**
* @deprecated OkHttp 1.5 enforces an enumeration of {@link Protocol
* protocols} that can be selected. Please switch to {@link
* #getProtocols()}.
*/
@Deprecated
public List<String> getTransports() {
List<String> transports = new ArrayList<String>(protocols.size());
for (int i = 0, size = protocols.size(); i < size; i++) {
transports.add(protocols.get(i).toString());
}
return transports;
}
public List<Protocol> getProtocols() {
return protocols;
}

View File

@@ -453,7 +453,7 @@ public class HttpURLConnectionImpl extends HttpURLConnection {
return Retry.NONE; // Don't follow redirects to unsupported protocols.
}
boolean sameProtocol = previousUrl.getProtocol().equals(url.getProtocol());
if (!sameProtocol && !client.getFollowProtocolRedirects()) {
if (!sameProtocol && !client.getFollowSslRedirects()) {
return Retry.NONE; // This client doesn't follow redirects across protocols.
}
boolean sameHost = previousUrl.getHost().equals(url.getHost());