mirror of
https://github.com/square/okhttp.git
synced 2026-01-18 20:40:58 +03:00
Forbid setProtocols with HTTP_1_0.
Closes https://github.com/square/okhttp/issues/986
This commit is contained in:
@@ -1393,8 +1393,7 @@ public final class CallTest {
|
||||
.matches("okhttp/\\d\\.\\d\\.\\d(-SNAPSHOT)?"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setFollowRedirectsFalse() throws Exception {
|
||||
@Test public void setFollowRedirectsFalse() throws Exception {
|
||||
server.enqueue(new MockResponse()
|
||||
.setResponseCode(302)
|
||||
.addHeader("Location: /b")
|
||||
|
||||
@@ -35,6 +35,7 @@ import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
public final class OkHttpClientTest {
|
||||
private static final ProxySelector DEFAULT_PROXY_SELECTOR = ProxySelector.getDefault();
|
||||
@@ -164,4 +165,13 @@ public final class OkHttpClientTest {
|
||||
Response actualResponse = mockClient.newCall(request).execute();
|
||||
assertSame(response, actualResponse);
|
||||
}
|
||||
|
||||
@Test public void setProtocolsRejectsHttp10() throws Exception {
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
try {
|
||||
client.setProtocols(Arrays.asList(Protocol.HTTP_1_0, Protocol.HTTP_1_1));
|
||||
fail();
|
||||
} catch (IllegalArgumentException expected) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -427,14 +427,22 @@ public class OkHttpClient implements Cloneable {
|
||||
* <a href="http://tools.ietf.org/html/draft-ietf-tls-applayerprotoneg">ALPN</a>
|
||||
* will be used to negotiate a transport.
|
||||
*
|
||||
* <p>{@link Protocol#HTTP_1_0} is not supported in this set. Requests are
|
||||
* initiated with {@code HTTP/1.1} only. If the server responds with {@code
|
||||
* HTTP/1.0}, that will be exposed by {@link Response#protocol()}.
|
||||
*
|
||||
* @param protocols the protocols to use, in order of preference. The list
|
||||
* must contain {@link Protocol#HTTP_1_1}. It must not contain null.
|
||||
* must contain {@link Protocol#HTTP_1_1}. It must not contain null or
|
||||
* {@link Protocol#HTTP_1_0}.
|
||||
*/
|
||||
public final OkHttpClient setProtocols(List<Protocol> protocols) {
|
||||
protocols = Util.immutableList(protocols);
|
||||
if (!protocols.contains(Protocol.HTTP_1_1)) {
|
||||
throw new IllegalArgumentException("protocols doesn't contain http/1.1: " + protocols);
|
||||
}
|
||||
if (protocols.contains(Protocol.HTTP_1_0)) {
|
||||
throw new IllegalArgumentException("protocols must not contain http/1.0: " + protocols);
|
||||
}
|
||||
if (protocols.contains(null)) {
|
||||
throw new IllegalArgumentException("protocols must not contain null");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user