1
0
mirror of https://github.com/square/okhttp.git synced 2025-12-25 00:01:02 +03:00

Fail HTTP/2 connections if the pong is not received. (#3878)

This removes the Ping abstraction from our http2 package. This was written as
if it were a public API, but never exposed to any callers but tests. Removing
it makes it easier to lock down how pings are used.

This also removes the NullServer class, replacing it with a new SocketPolicy
on MockWebServer. The new SocketPolicy, STALL_SOCKET_AT_START, allows us to
do TLS and negotiate an HTTP/2 connection without actually building a proper
Http2Connection and without responding to pings.

The behavior in HTTP/2 connections is modeled after our behavior in web sockets.
We count outgoing pings, incoming pongs, and confirm that the pongs are keeping
up. If later we make this policy more sophisticated we can track the changes
in both places.

Closes: https://github.com/square/okhttp/issues/3261
This commit is contained in:
Jesse Wilson
2018-02-22 18:37:34 -05:00
committed by GitHub
parent b6e32b4fb0
commit af6198a1e9
8 changed files with 128 additions and 266 deletions

View File

@@ -91,6 +91,7 @@ import static okhttp3.mockwebserver.SocketPolicy.NO_RESPONSE;
import static okhttp3.mockwebserver.SocketPolicy.RESET_STREAM_AT_START;
import static okhttp3.mockwebserver.SocketPolicy.SHUTDOWN_INPUT_AT_END;
import static okhttp3.mockwebserver.SocketPolicy.SHUTDOWN_OUTPUT_AT_END;
import static okhttp3.mockwebserver.SocketPolicy.STALL_SOCKET_AT_START;
import static okhttp3.mockwebserver.SocketPolicy.UPGRADE_TO_SSL_AT_END;
/**
@@ -406,13 +407,13 @@ public final class MockWebServer extends ExternalResource implements Closeable {
}
public void processConnection() throws Exception {
SocketPolicy socketPolicy = dispatcher.peek().getSocketPolicy();
Protocol protocol = Protocol.HTTP_1_1;
Socket socket;
if (sslSocketFactory != null) {
if (tunnelProxy) {
createTunnel();
}
SocketPolicy socketPolicy = dispatcher.peek().getSocketPolicy();
if (socketPolicy == FAIL_HANDSHAKE) {
dispatchBookkeepingRequest(sequenceNumber, raw);
processHandshakeFailure(raw);
@@ -439,6 +440,10 @@ public final class MockWebServer extends ExternalResource implements Closeable {
socket = raw;
}
if (socketPolicy == STALL_SOCKET_AT_START) {
return; // Ignore the socket until the server is shut down!
}
if (protocol == Protocol.HTTP_2) {
Http2SocketHandler http2SocketHandler = new Http2SocketHandler(socket, protocol);
Http2Connection connection = new Http2Connection.Builder(false)

View File

@@ -88,8 +88,14 @@ public enum SocketPolicy {
SHUTDOWN_OUTPUT_AT_END,
/**
* Don't respond to the request but keep the socket open. For testing read response header timeout
* issue.
* After accepting the connection and doing TLS (if configured) don't do HTTP/1.1 or HTTP/2
* framing. Ignore the socket completely until the server is shut down.
*/
STALL_SOCKET_AT_START,
/**
* Read the request but don't respond to it. Just keep the socket open. For testing read response
* header timeout issue.
*/
NO_RESPONSE,