use of io.servicetalk.http.api.StreamingHttpConnection in project servicetalk by apple.
the class FullDuplexAndSequentialModeTest method defaultFullDuplex.
@Test
void defaultFullDuplex() throws Exception {
setUp(CACHED, CACHED_SERVER);
StreamingHttpConnection connection = streamingHttpConnection();
CountDownLatch continueRequest = new CountDownLatch(1);
StreamingHttpResponse response;
try (InputStream payload = payload()) {
response = stallingSendRequest(connection, continueRequest, payload).get();
// response meta-data received before request completes
assertResponse(response, HTTP_1_1, OK);
}
continueRequest.countDown();
ExecutionException e = assertThrows(ExecutionException.class, () -> response.payloadBody().toFuture().get());
assertThat(e.getCause(), instanceOf(IOException.class));
assertThat(e.getCause().getMessage(), containsString("Stream closed"));
}
use of io.servicetalk.http.api.StreamingHttpConnection in project servicetalk by apple.
the class H2ResponseCancelTest method testServerClosesStreamNotConnection.
@Test
void testServerClosesStreamNotConnection() throws Exception {
StreamingHttpConnection connection = streamingHttpConnection();
AtomicBoolean connectionClosed = new AtomicBoolean();
connection.onClose().whenFinally(() -> connectionClosed.set(true)).subscribe();
ExecutionException e = assertThrows(ExecutionException.class, () -> makeRequest(newRequest(connection, "close")));
assertThat(e.getCause(), instanceOf(H2StreamResetException.class));
// Mak sure we can use the same connection for future requests:
assertSerializedResponse(makeRequest(newRequest(connection, "ok")), HTTP_2_0, OK, "ok");
assertThat("Connection closed unexpectedly", connectionClosed.get(), is(false));
}
use of io.servicetalk.http.api.StreamingHttpConnection in project servicetalk by apple.
the class HttpTransportObserverTest method connectionEstablished.
@ParameterizedTest(name = "protocol={0}")
@EnumSource(HttpProtocol.class)
void connectionEstablished(HttpProtocol httpProtocol) throws Exception {
setUp(httpProtocol);
processRequest.countDown();
StreamingHttpConnection connection = streamingHttpConnection();
verify(clientTransportObserver).onNewConnection(any(), any());
verify(serverTransportObserver, await()).onNewConnection(any(), any());
verify(clientConnectionObserver).onTransportHandshakeComplete();
verify(serverConnectionObserver, await()).onTransportHandshakeComplete();
if (protocol == HTTP_1) {
verify(clientConnectionObserver).connectionEstablished(any(ConnectionInfo.class));
verify(serverConnectionObserver, await()).connectionEstablished(any(ConnectionInfo.class));
verify(serverDataObserver, await()).onNewRead();
verify(serverDataObserver, await()).onNewWrite();
} else {
verify(clientConnectionObserver).multiplexedConnectionEstablished(any(ConnectionInfo.class));
verify(serverConnectionObserver, await()).multiplexedConnectionEstablished(any(ConnectionInfo.class));
}
connection.closeGracefully();
assertConnectionClosed();
verify(clientConnectionObserver).connectionClosed();
verify(serverConnectionObserver, await()).connectionClosed();
verifyNoMoreInteractions(clientTransportObserver, clientDataObserver, clientMultiplexedObserver, serverTransportObserver, serverDataObserver, serverMultiplexedObserver);
if (protocol != HTTP_2) {
// HTTP/2 coded adds additional write/flush events related to connection preface. Also, it may emit more
// flush events on the pipeline after the connection is closed.
verifyNoMoreInteractions(clientConnectionObserver, serverConnectionObserver);
}
}
use of io.servicetalk.http.api.StreamingHttpConnection in project servicetalk by apple.
the class IllegalHeaderValueTest method noHeaderValueValidation.
@ParameterizedTest(name = "{index}: protocol={0}")
@EnumSource(HttpProtocol.class)
void noHeaderValueValidation(HttpProtocol protocol) throws Exception {
protocol(config(protocol, false));
setUp(CACHED, CACHED_SERVER);
StreamingHttpConnection connection = streamingHttpConnection();
StreamingHttpResponse response = requestWithInvalidHeader(connection);
assertResponse(response, protocol.version, OK, 0);
if (protocol == HTTP_1) {
// HTTP/1.1 will try parsing the X_HEADER_NAME as a new request and fail, closing the connection:
ExecutionException e = assertThrows(ExecutionException.class, () -> requestWithInvalidHeader(connection));
assertThat(e.getCause(), instanceOf(IOException.class));
} else {
// HTTP/2 uses binary encoding and can transfer illegal header values with not problem:
StreamingHttpResponse secondResponse = requestWithInvalidHeader(connection);
assertResponse(secondResponse, protocol.version, OK, 0);
}
}
Aggregations