use of io.servicetalk.http.api.HttpServerBuilder in project servicetalk by apple.
the class MutualSslTest method mutualSsl.
@ParameterizedTest
@MethodSource("params")
void mutualSsl(SslProvider serverSslProvider, SslProvider clientSslProvider, @SuppressWarnings("rawtypes") Map<SocketOption, Object> serverListenOptions, @SuppressWarnings("rawtypes") Map<SocketOption, Object> clientOptions) throws Exception {
assumeTcpFastOpen(clientOptions);
HttpServerBuilder serverBuilder = HttpServers.forAddress(localAddress(0)).sslConfig(new ServerSslConfigBuilder(DefaultTestCerts::loadServerPem, DefaultTestCerts::loadServerKey).trustManager(DefaultTestCerts::loadClientCAPem).clientAuthMode(REQUIRE).provider(serverSslProvider).build());
for (@SuppressWarnings("rawtypes") Entry<SocketOption, Object> entry : serverListenOptions.entrySet()) {
@SuppressWarnings("unchecked") SocketOption<Object> option = entry.getKey();
serverBuilder.listenSocketOption(option, entry.getValue());
}
try (ServerContext serverContext = serverBuilder.listenBlockingAndAwait((ctx, request, responseFactory) -> responseFactory.ok());
BlockingHttpClient client = newClientBuilder(serverContext, clientOptions).sslConfig(new ClientSslConfigBuilder(DefaultTestCerts::loadServerCAPem).provider(clientSslProvider).peerHost(serverPemHostname()).keyManager(DefaultTestCerts::loadClientPem, DefaultTestCerts::loadClientKey).build()).buildBlocking()) {
assertEquals(HttpResponseStatus.OK, client.request(client.get("/")).status());
}
}
use of io.servicetalk.http.api.HttpServerBuilder in project servicetalk by apple.
the class InvokingThreadsRecorder method init.
void init(BiFunction<IoExecutor, HttpServerBuilder, Single<HttpServerContext>> serverStarter, BiConsumer<IoExecutor, SingleAddressHttpClientBuilder<HostAndPort, InetSocketAddress>> clientUpdater) {
try {
HttpServerBuilder serverBuilder = HttpServers.forAddress(localAddress(0));
context = serverStarter.apply(ioExecutor, serverBuilder).toFuture().get();
} catch (Exception e) {
fail("Exception in initialization", e);
}
SingleAddressHttpClientBuilder<HostAndPort, InetSocketAddress> clientBuilder = HttpClients.forSingleAddress(serverHostAndPort(context));
clientUpdater.accept(ioExecutor, clientBuilder);
client = clientBuilder.buildStreaming();
}
use of io.servicetalk.http.api.HttpServerBuilder in project servicetalk by apple.
the class NettyHttpServerTest method testServiceThrowsReturnsErrorResponse.
@ParameterizedTest(name = "{displayName} [{index}] disableOffloading={0}")
@ValueSource(booleans = { true, false })
void testServiceThrowsReturnsErrorResponse(boolean disableOffloading) throws Exception {
// the test suite state isn't used by this individual test, but cleanup code requires it is initialized.
setUp(IMMEDIATE, IMMEDIATE);
HttpServerBuilder serverBuilder = HttpServers.forAddress(localAddress(0));
if (disableOffloading) {
serverBuilder.executionStrategy(offloadNever());
}
try (ServerContext serverCtx = serverBuilder.listenStreamingAndAwait((ctx, request, responseFactory) -> {
throw DELIBERATE_EXCEPTION;
});
BlockingHttpClient client = disableOffloading(HttpClients.forResolvedAddress(serverHostAndPort(serverCtx)), disableOffloading).buildBlocking()) {
HttpResponse resp = client.request(client.get("/"));
assertThat(resp.status(), is(INTERNAL_SERVER_ERROR));
}
}
use of io.servicetalk.http.api.HttpServerBuilder in project servicetalk by apple.
the class BasicAuthStrategyInfluencerTest method setup.
private BlockingHttpClient setup(boolean noOffloadsInfluence) throws Exception {
ioExecutor = NettyIoExecutors.createIoExecutor(IO_EXECUTOR_NAME_PREFIX);
HttpServerBuilder serverBuilder = HttpServers.forAddress(localAddress(0));
when(credentialsVerifier.apply(anyString(), anyString())).thenReturn(succeeded("success"));
when(credentialsVerifier.closeAsync()).thenReturn(completed());
when(credentialsVerifier.closeAsyncGracefully()).thenReturn(completed());
CredentialsVerifier<String> verifier = credentialsVerifier;
if (noOffloadsInfluence) {
verifier = new InfluencingVerifier(verifier, offloadNone());
serverBuilder.executionStrategy(offloadNever());
}
serverBuilder.appendServiceFilter(new BasicAuthHttpServiceFilter.Builder<>(verifier, "dummy").buildServer());
serverBuilder.ioExecutor(ioExecutor);
service = new OffloadCheckingService();
serverContext = serverBuilder.listenStreamingAndAwait(service);
SingleAddressHttpClientBuilder<HostAndPort, InetSocketAddress> clientBuilder = HttpClients.forSingleAddress(serverHostAndPort(serverContext));
this.client = clientBuilder.buildBlocking();
return this.client;
}
use of io.servicetalk.http.api.HttpServerBuilder in project servicetalk by apple.
the class HttpProtocolConfigTest method serverWithUnsupportedProtocolConfig.
@Test
void serverWithUnsupportedProtocolConfig() {
HttpServerBuilder builder = HttpServers.forAddress(localAddress(0));
Exception e = assertThrows(IllegalArgumentException.class, () -> builder.protocols(UNKNOWN_CONFIG));
assertThat(e.getMessage(), startsWith("Unsupported HttpProtocolConfig"));
}
Aggregations