Skip to content

Commit

Permalink
Drop support for SPDY/3.
Browse files Browse the repository at this point in the history
It's redundant with HTTP/2.
  • Loading branch information
squarejesse committed Jul 9, 2016
1 parent a3bcaa3 commit 0c04821
Show file tree
Hide file tree
Showing 46 changed files with 2,771 additions and 4,720 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ Snapshots of the development version are available in [Sonatype's `snapshots` re
MockWebServer
-------------

A library for testing HTTP, HTTPS, HTTP/2.0, and SPDY clients.
A library for testing HTTP, HTTPS, and HTTP/2 clients.

MockWebServer coupling with OkHttp is essential for proper testing of HTTP/2.0 so that code can be shared.
MockWebServer coupling with OkHttp is essential for proper testing of HTTP/2 so that code can be shared.

### Download

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/src/main/java/okhttp3/benchmarks/Benchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class Benchmark extends com.google.caliper.Benchmark {
@Param
boolean gzip;

/** Don't combine chunked with SPDY_3 or HTTP_2; that's not allowed. */
/** Don't combine chunked with HTTP_2; that's not allowed. */
@Param
boolean chunked;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand All @@ -37,13 +38,10 @@

import static okhttp3.internal.platform.Platform.INFO;

/** A basic SPDY/HTTP_2 server that serves the contents of a local directory. */
/** A basic HTTP_2 server that serves the contents of a local directory. */
public final class FramedServer extends FramedConnection.Listener {
static final Logger logger = Logger.getLogger(FramedServer.class.getName());

private final List<Protocol> framedProtocols =
Util.immutableList(Protocol.HTTP_2, Protocol.SPDY_3);

private final File baseDirectory;
private final SSLSocketFactory sslSocketFactory;

Expand All @@ -64,12 +62,11 @@ private void run() throws Exception {
SSLSocket sslSocket = doSsl(socket);
String protocolString = Platform.get().getSelectedProtocol(sslSocket);
Protocol protocol = protocolString != null ? Protocol.get(protocolString) : null;
if (protocol == null || !framedProtocols.contains(protocol)) {
if (protocol != Protocol.HTTP_2) {
throw new ProtocolException("Protocol " + protocol + " unsupported");
}
FramedConnection framedConnection = new FramedConnection.Builder(false)
.socket(sslSocket)
.protocol(protocol)
.listener(this)
.build();
framedConnection.start();
Expand All @@ -87,7 +84,8 @@ private SSLSocket doSsl(Socket socket) throws IOException {
SSLSocket sslSocket = (SSLSocket) sslSocketFactory.createSocket(
socket, socket.getInetAddress().getHostAddress(), socket.getPort(), true);
sslSocket.setUseClientMode(false);
Platform.get().configureTlsExtensions(sslSocket, null, framedProtocols);
Platform.get().configureTlsExtensions(sslSocket, null,
Collections.singletonList(Protocol.HTTP_2));
sslSocket.startHandshake();
return sslSocket;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ public final class MockWebServer implements TestRule {
private int port = -1;
private InetSocketAddress inetSocketAddress;
private boolean protocolNegotiationEnabled = true;
private List<Protocol> protocols
= Util.immutableList(Protocol.HTTP_2, Protocol.SPDY_3, Protocol.HTTP_1_1);
private List<Protocol> protocols = Util.immutableList(Protocol.HTTP_2, Protocol.HTTP_1_1);

private boolean started;

Expand Down Expand Up @@ -450,17 +449,18 @@ public void processConnection() throws Exception {
socket = raw;
}

if (protocol != Protocol.HTTP_1_1) {
if (protocol == Protocol.HTTP_2) {
FramedSocketHandler framedSocketListener = new FramedSocketHandler(socket, protocol);
FramedConnection framedConnection = new FramedConnection.Builder(false)
.socket(socket)
.protocol(protocol)
.listener(framedSocketListener)
.build();
framedConnection.start();
openFramedConnections.add(framedConnection);
openClientSockets.remove(socket);
return;
} else if (protocol != Protocol.HTTP_1_1) {
throw new AssertionError();
}

BufferedSource source = Okio.buffer(Okio.source(socket));
Expand Down Expand Up @@ -885,20 +885,13 @@ private RecordedRequest readRequest(FramedStream stream) throws IOException {
Headers.Builder httpHeaders = new Headers.Builder();
String method = "<:method omitted>";
String path = "<:path omitted>";
String version = protocol == Protocol.SPDY_3 ? "<:version omitted>" : "HTTP/1.1";
for (int i = 0, size = streamHeaders.size(); i < size; i++) {
ByteString name = streamHeaders.get(i).name;
String value = streamHeaders.get(i).value.utf8();
if (name.equals(Header.TARGET_METHOD)) {
method = value;
} else if (name.equals(Header.TARGET_PATH)) {
path = value;
} else if (name.equals(Header.VERSION)) {
version = value;
} else if (protocol == Protocol.SPDY_3) {
for (String s : value.split("\u0000", -1)) {
httpHeaders.add(name.utf8(), s);
}
} else if (protocol == Protocol.HTTP_2) {
httpHeaders.add(name.utf8(), value);
} else {
Expand All @@ -910,8 +903,8 @@ private RecordedRequest readRequest(FramedStream stream) throws IOException {
body.writeAll(stream.getSource());
body.close();

String requestLine = method + ' ' + path + ' ' + version;
List<Integer> chunkSizes = Collections.emptyList(); // No chunked encoding for SPDY.
String requestLine = method + ' ' + path + " HTTP/1.1";
List<Integer> chunkSizes = Collections.emptyList(); // No chunked encoding for HTTP/2.
return new RecordedRequest(requestLine, httpHeaders.build(), chunkSizes, body.size(), body,
sequenceNumber.getAndIncrement(), socket);
}
Expand All @@ -925,24 +918,21 @@ private void writeResponse(FramedStream stream, MockResponse response) throws IO
if (response.getSocketPolicy() == NO_RESPONSE) {
return;
}
List<Header> spdyHeaders = new ArrayList<>();
List<Header> http2Headers = new ArrayList<>();
String[] statusParts = response.getStatus().split(" ", 2);
if (statusParts.length != 2) {
throw new AssertionError("Unexpected status: " + response.getStatus());
}
// TODO: constants for well-known header names.
spdyHeaders.add(new Header(Header.RESPONSE_STATUS, statusParts[1]));
if (protocol == Protocol.SPDY_3) {
spdyHeaders.add(new Header(Header.VERSION, statusParts[0]));
}
http2Headers.add(new Header(Header.RESPONSE_STATUS, statusParts[1]));
Headers headers = response.getHeaders();
for (int i = 0, size = headers.size(); i < size; i++) {
spdyHeaders.add(new Header(headers.name(i), headers.value(i)));
http2Headers.add(new Header(headers.name(i), headers.value(i)));
}

Buffer body = response.getBody();
boolean closeStreamAfterHeaders = body != null || !response.getPushPromises().isEmpty();
stream.reply(spdyHeaders, closeStreamAfterHeaders);
stream.reply(http2Headers, closeStreamAfterHeaders);
pushPromises(stream, response.getPushPromises());
if (body != null) {
BufferedSink sink = Okio.buffer(stream.getSink());
Expand All @@ -957,17 +947,15 @@ private void writeResponse(FramedStream stream, MockResponse response) throws IO
private void pushPromises(FramedStream stream, List<PushPromise> promises) throws IOException {
for (PushPromise pushPromise : promises) {
List<Header> pushedHeaders = new ArrayList<>();
pushedHeaders.add(new Header(stream.getConnection().getProtocol() == Protocol.SPDY_3
? Header.TARGET_HOST
: Header.TARGET_AUTHORITY, url(pushPromise.path()).host()));
pushedHeaders.add(new Header(Header.TARGET_AUTHORITY, url(pushPromise.path()).host()));
pushedHeaders.add(new Header(Header.TARGET_METHOD, pushPromise.method()));
pushedHeaders.add(new Header(Header.TARGET_PATH, pushPromise.path()));
Headers pushPromiseHeaders = pushPromise.headers();
for (int i = 0, size = pushPromiseHeaders.size(); i < size; i++) {
pushedHeaders.add(new Header(pushPromiseHeaders.name(i), pushPromiseHeaders.value(i)));
}
String requestLine = pushPromise.method() + ' ' + pushPromise.path() + " HTTP/1.1";
List<Integer> chunkSizes = Collections.emptyList(); // No chunked encoding for SPDY.
List<Integer> chunkSizes = Collections.emptyList(); // No chunked encoding for HTTP/2.
requestQueue.add(new RecordedRequest(requestLine, pushPromise.headers(), chunkSizes, 0,
new Buffer(), sequenceNumber.getAndIncrement(), socket));
boolean hasBody = pushPromise.response().getBody() != null;
Expand Down
2 changes: 1 addition & 1 deletion okcurl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ OkCurl
_A curl for the next-generation web._

OkCurl is an OkHttp-backed curl clone which allows you to test OkHttp's HTTP engine (including
SPDY and HTTP/2) against web servers.
HTTP/2) against web servers.
71 changes: 0 additions & 71 deletions okhttp-tests/src/test/java/okhttp3/CallTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,6 @@ public final class CallTest {
get();
}

@Test public void get_SPDY_3() throws Exception {
enableProtocol(Protocol.SPDY_3);
get();
}

@Test public void repeatedHeaderNames() throws Exception {
server.enqueue(new MockResponse()
.addHeader("B", "123")
Expand All @@ -199,11 +194,6 @@ public final class CallTest {
assertEquals(Arrays.asList("345", "456"), recordedRequest.getHeaders().values("A"));
}

@Test public void repeatedHeaderNames_SPDY_3() throws Exception {
enableProtocol(Protocol.SPDY_3);
repeatedHeaderNames();
}

@Test public void repeatedHeaderNames_HTTP_2() throws Exception {
enableProtocol(Protocol.HTTP_2);
repeatedHeaderNames();
Expand Down Expand Up @@ -249,11 +239,6 @@ public final class CallTest {
head();
}

@Test public void head_SPDY_3() throws Exception {
enableProtocol(Protocol.SPDY_3);
head();
}

@Test public void post() throws Exception {
server.enqueue(new MockResponse().setBody("abc"));

Expand Down Expand Up @@ -283,11 +268,6 @@ public final class CallTest {
post();
}

@Test public void post_SPDY_3() throws Exception {
enableProtocol(Protocol.SPDY_3);
post();
}

@Test public void postZeroLength() throws Exception {
server.enqueue(new MockResponse().setBody("abc"));

Expand Down Expand Up @@ -317,11 +297,6 @@ public final class CallTest {
postZeroLength();
}

@Test public void postZeroLength_SPDY_3() throws Exception {
enableProtocol(Protocol.SPDY_3);
postZeroLength();
}

@Test public void postBodyRetransmittedAfterAuthorizationFail() throws Exception {
postBodyRetransmittedAfterAuthorizationFail("abc");
}
Expand All @@ -336,11 +311,6 @@ public final class CallTest {
postBodyRetransmittedAfterAuthorizationFail("abc");
}

@Test public void postBodyRetransmittedAfterAuthorizationFail_SPDY_3() throws Exception {
enableProtocol(Protocol.SPDY_3);
postBodyRetransmittedAfterAuthorizationFail("abc");
}

/** Don't explode when resending an empty post. https://github.com/square/okhttp/issues/1131 */
@Test public void postEmptyBodyRetransmittedAfterAuthorizationFail() throws Exception {
postBodyRetransmittedAfterAuthorizationFail("");
Expand All @@ -356,11 +326,6 @@ public final class CallTest {
postBodyRetransmittedAfterAuthorizationFail("");
}

@Test public void postEmptyBodyRetransmittedAfterAuthorizationFail_SPDY_3() throws Exception {
enableProtocol(Protocol.SPDY_3);
postBodyRetransmittedAfterAuthorizationFail("");
}

private void postBodyRetransmittedAfterAuthorizationFail(String body) throws Exception {
server.enqueue(new MockResponse().setResponseCode(401));
server.enqueue(new MockResponse());
Expand Down Expand Up @@ -452,11 +417,6 @@ private void postBodyRetransmittedAfterAuthorizationFail(String body) throws Exc
delete();
}

@Test public void delete_SPDY_3() throws Exception {
enableProtocol(Protocol.SPDY_3);
delete();
}

@Test public void deleteWithRequestBody() throws Exception {
server.enqueue(new MockResponse().setBody("abc"));

Expand Down Expand Up @@ -503,11 +463,6 @@ private void postBodyRetransmittedAfterAuthorizationFail(String body) throws Exc
put();
}

@Test public void put_SPDY_3() throws Exception {
enableProtocol(Protocol.SPDY_3);
put();
}

@Test public void patch() throws Exception {
server.enqueue(new MockResponse().setBody("abc"));

Expand Down Expand Up @@ -537,11 +492,6 @@ private void postBodyRetransmittedAfterAuthorizationFail(String body) throws Exc
patch();
}

@Test public void patch_SPDY_3() throws Exception {
enableProtocol(Protocol.SPDY_3);
patch();
}

@Test public void unspecifiedRequestBodyContentTypeDoesNotGetDefault() throws Exception {
server.enqueue(new MockResponse());

Expand Down Expand Up @@ -1854,11 +1804,6 @@ private InetSocketAddress startNullServer() throws IOException {
cancelInFlightBeforeResponseReadThrowsIOE();
}

@Test public void cancelInFlightBeforeResponseReadThrowsIOE_SPDY_3() throws Exception {
enableProtocol(Protocol.SPDY_3);
cancelInFlightBeforeResponseReadThrowsIOE();
}

/**
* This test puts a request in front of one that is to be canceled, so that it is canceled before
* I/O takes place.
Expand Down Expand Up @@ -1904,11 +1849,6 @@ private InetSocketAddress startNullServer() throws IOException {
canceledBeforeIOSignalsOnFailure();
}

@Test public void canceledBeforeIOSignalsOnFailure_SPDY_3() throws Exception {
enableProtocol(Protocol.SPDY_3);
canceledBeforeIOSignalsOnFailure();
}

@Test public void canceledBeforeResponseReadSignalsOnFailure() throws Exception {
Request requestA = new Request.Builder().url(server.url("/a")).build();
final Call call = client.newCall(requestA);
Expand Down Expand Up @@ -1936,11 +1876,6 @@ private InetSocketAddress startNullServer() throws IOException {
canceledBeforeResponseReadSignalsOnFailure();
}

@Test public void canceledBeforeResponseReadSignalsOnFailure_SPDY_3() throws Exception {
enableProtocol(Protocol.SPDY_3);
canceledBeforeResponseReadSignalsOnFailure();
}

/**
* There's a race condition where the cancel may apply after the stream has already been
* processed.
Expand Down Expand Up @@ -1990,12 +1925,6 @@ private InetSocketAddress startNullServer() throws IOException {
canceledAfterResponseIsDeliveredBreaksStreamButSignalsOnce();
}

@Test public void canceledAfterResponseIsDeliveredBreaksStreamButSignalsOnce_SPDY_3()
throws Exception {
enableProtocol(Protocol.SPDY_3);
canceledAfterResponseIsDeliveredBreaksStreamButSignalsOnce();
}

@Test public void cancelWithInterceptor() throws Exception {
client = client.newBuilder()
.addInterceptor(new Interceptor() {
Expand Down
Loading

0 comments on commit 0c04821

Please sign in to comment.