Search in sources :

Example 1 with BlockingHttpConnection

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()));
    }
}
Also used : ServerContext(io.servicetalk.transport.api.ServerContext) BlockingHttpConnection(io.servicetalk.http.api.BlockingHttpConnection) BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with BlockingHttpConnection

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);
    }
}
Also used : ServerContext(io.servicetalk.transport.api.ServerContext) BlockingHttpConnection(io.servicetalk.http.api.BlockingHttpConnection) BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient)

Example 3 with BlockingHttpConnection

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())));
    }
}
Also used : ServerContext(io.servicetalk.transport.api.ServerContext) BlockingHttpConnection(io.servicetalk.http.api.BlockingHttpConnection) BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with BlockingHttpConnection

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));
        }
    }
}
Also used : SslConfig(io.servicetalk.transport.api.SslConfig) ServerContext(io.servicetalk.transport.api.ServerContext) BlockingHttpConnection(io.servicetalk.http.api.BlockingHttpConnection) BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) SSLSession(javax.net.ssl.SSLSession) HttpResponse(io.servicetalk.http.api.HttpResponse) DefaultTestCerts(io.servicetalk.test.resources.DefaultTestCerts) ClientSslConfigBuilder(io.servicetalk.transport.api.ClientSslConfigBuilder) ServerSslConfigBuilder(io.servicetalk.transport.api.ServerSslConfigBuilder) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

BlockingHttpClient (io.servicetalk.http.api.BlockingHttpClient)4 BlockingHttpConnection (io.servicetalk.http.api.BlockingHttpConnection)4 ServerContext (io.servicetalk.transport.api.ServerContext)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 EnumSource (org.junit.jupiter.params.provider.EnumSource)2 HttpResponse (io.servicetalk.http.api.HttpResponse)1 DefaultTestCerts (io.servicetalk.test.resources.DefaultTestCerts)1 ClientSslConfigBuilder (io.servicetalk.transport.api.ClientSslConfigBuilder)1 ServerSslConfigBuilder (io.servicetalk.transport.api.ServerSslConfigBuilder)1 SslConfig (io.servicetalk.transport.api.SslConfig)1 SSLSession (javax.net.ssl.SSLSession)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1