use of io.servicetalk.http.api.BlockingHttpConnection in project servicetalk by apple.
the class HttpConnectionContextProtocolTest method testProtocol.
@ParameterizedTest
@EnumSource(Config.class)
void testProtocol(Config config) throws Exception {
try (ServerContext serverContext = startServer(config);
BlockingHttpClient client = newClient(serverContext, config);
BlockingHttpConnection connection = client.reserveConnection(client.get("/"))) {
assertThat("Client-side connection protocol does not match expected value", connection.connectionContext().protocol(), equalTo(config.expectedProtocol));
assertThat("Server-side connection protocol does not match expected value", connection.request(connection.get("/")).payloadBody(textSerializerUtf8()), equalTo(config.expectedProtocol.name()));
}
}
use of io.servicetalk.http.api.BlockingHttpConnection in project servicetalk by apple.
the class HttpConnectionContextSocketOptionTest method testSocketOption.
private static <T> void testSocketOption(SocketOption<T> socketOption, Matcher<Object> clientMatcher, Matcher<Object> serverMatcher, @Nullable Long idleTimeoutMs, HttpProtocol protocol) throws Exception {
try (ServerContext serverContext = startServer(idleTimeoutMs, socketOption, protocol);
BlockingHttpClient client = newClient(serverContext, idleTimeoutMs, protocol);
BlockingHttpConnection connection = client.reserveConnection(client.get("/"))) {
assertThat("Client-side connection SocketOption does not match expected value", connection.connectionContext().socketOption(socketOption), clientMatcher);
assertThat("Server-side connection SocketOption does not match expected value", connection.request(connection.get("/")).payloadBody(textSerializerUtf8()), serverMatcher);
}
}
use of io.servicetalk.http.api.BlockingHttpConnection in project servicetalk by apple.
the class HttpConnectionContextSocketOptionTest method unsupportedSocketOptionThrows.
@ParameterizedTest(name = "protocol={0}")
@EnumSource(HttpProtocol.class)
void unsupportedSocketOptionThrows(HttpProtocol protocol) throws Exception {
final SocketOption<Boolean> unsupported = new CustomSocketOption<>("UNSUPPORTED", Boolean.class);
try (ServerContext serverContext = HttpServers.forAddress(localAddress(0)).protocols(protocol.config).listenBlockingAndAwait((ctx, request, responseFactory) -> {
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> ctx.socketOption(unsupported));
return responseFactory.ok().payloadBody(ex.getMessage(), textSerializerUtf8());
});
BlockingHttpClient client = HttpClients.forSingleAddress(serverHostAndPort(serverContext)).protocols(protocol.config).buildBlocking();
BlockingHttpConnection connection = client.reserveConnection(client.get("/"))) {
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> connection.connectionContext().socketOption(unsupported));
assertThat(ex.getMessage(), endsWith("not supported"));
assertThat(ex.getMessage(), equalTo(connection.request(connection.get("/")).payloadBody(textSerializerUtf8())));
}
}
use of io.servicetalk.http.api.BlockingHttpConnection in project servicetalk by apple.
the class Tls13Test method requiredCipher.
@ParameterizedTest
@MethodSource("sslProviders")
void requiredCipher(SslProvider serverSslProvider, SslProvider clientSslProvider, @Nullable String cipher) throws Exception {
ServerSslConfigBuilder serverSslBuilder = new ServerSslConfigBuilder(DefaultTestCerts::loadServerPem, DefaultTestCerts::loadServerKey).sslProtocols(TLS1_3).provider(serverSslProvider);
if (cipher != null) {
serverSslBuilder.ciphers(singletonList(cipher));
}
try (ServerContext serverContext = forAddress(localAddress(0)).ioExecutor(SERVER_CTX.ioExecutor()).executor(SERVER_CTX.executor()).executionStrategy(defaultStrategy()).enableWireLogging("servicetalk-tests-wire-logger", TRACE, () -> false).sslConfig(serverSslBuilder.build()).listenBlockingAndAwait((ctx, request, responseFactory) -> {
assertThat(request.payloadBody(textSerializerUtf8()), equalTo("request-payload-body"));
SslConfig sslConfig = ctx.sslConfig();
assertThat(sslConfig, is(notNullValue()));
assertThat(sslConfig.sslProtocols(), contains(TLS1_3));
SSLSession sslSession = ctx.sslSession();
assertThat(sslSession, is(notNullValue()));
return responseFactory.ok().payloadBody(sslSession.getProtocol(), textSerializerUtf8());
})) {
ClientSslConfigBuilder clientSslBuilder = new ClientSslConfigBuilder(DefaultTestCerts::loadServerCAPem).sslProtocols(TLS1_3).peerHost(serverPemHostname()).provider(clientSslProvider);
if (cipher != null) {
clientSslBuilder.ciphers(singletonList(cipher));
}
try (BlockingHttpClient client = HttpClients.forSingleAddress(serverHostAndPort(serverContext)).ioExecutor(CLIENT_CTX.ioExecutor()).executor(CLIENT_CTX.executor()).executionStrategy(defaultStrategy()).enableWireLogging("servicetalk-tests-wire-logger", TRACE, Boolean.FALSE::booleanValue).sslConfig(clientSslBuilder.build()).buildBlocking();
BlockingHttpConnection connection = client.reserveConnection(client.get("/"))) {
SslConfig sslConfig = connection.connectionContext().sslConfig();
assertThat(sslConfig, is(notNullValue()));
assertThat(sslConfig.sslProtocols(), contains(TLS1_3));
SSLSession sslSession = connection.connectionContext().sslSession();
assertThat(sslSession, is(notNullValue()));
assertThat(sslSession.getProtocol(), equalTo(TLS1_3));
if (cipher != null) {
assertThat(sslSession.getCipherSuite(), equalTo(cipher));
}
HttpResponse response = client.request(client.post("/").payloadBody("request-payload-body", textSerializerUtf8()));
assertThat(response.status(), is(OK));
assertThat(response.headers().get(CONTENT_TYPE), is(TEXT_PLAIN_UTF_8));
assertThat(response.payloadBody(textSerializerUtf8()), equalTo(TLS1_3));
}
}
}
Aggregations