use of io.servicetalk.http.api.HttpServerBuilder in project servicetalk by apple.
the class NettyHttpServerConnectionDrainTest method server.
private static ServerContext server(boolean autoDrain, StreamingHttpService handler) throws Exception {
HttpServerBuilder httpServerBuilder = HttpServers.forAddress(AddressUtils.localAddress(0));
if (!autoDrain) {
httpServerBuilder = httpServerBuilder.drainRequestPayloadBody(false);
}
ServerContext serverContext = httpServerBuilder.listenStreamingAndAwait(handler);
return new ServerContext() {
@Override
public SocketAddress listenAddress() {
return serverContext.listenAddress();
}
@Override
public ExecutionContext<?> executionContext() {
return serverContext.executionContext();
}
@Override
public void acceptConnections(final boolean accept) {
serverContext.acceptConnections(accept);
}
@Override
public Completable onClose() {
return serverContext.onClose();
}
@Override
public Completable closeAsync() {
return serverContext.closeAsync();
}
@Override
public void close() {
// Without draining the request is expected to hang, don't wait too long unless on CI
int timeoutSeconds = CI ? 15 : 1;
awaitTermination(serverContext.closeAsyncGracefully().timeout(timeoutSeconds, SECONDS).onErrorResume(t -> serverContext.closeAsync().concat(Completable.failed(t))).toFuture());
}
};
}
use of io.servicetalk.http.api.HttpServerBuilder in project servicetalk by apple.
the class ServiceTalkContentCodingTest method newServiceTalkServer.
private ServerContext newServiceTalkServer(final Scenario scenario, final Queue<Throwable> errors) throws Exception {
HttpServerBuilder httpServerBuilder = HttpServers.forAddress(localAddress(0));
StreamingHttpService service = (ctx, request, responseFactory) -> succeeded(buildResponse(responseFactory));
StreamingHttpServiceFilterFactory filterFactory = REQ_FILTER.apply(scenario, errors);
return httpServerBuilder.executionStrategy(defaultStrategy()).protocols(scenario.protocol.config).appendServiceFilter(new ContentCodingHttpServiceFilter(scenario.serverSupported, scenario.serverSupported)).appendServiceFilter(filterFactory).listenStreamingAndAwait(service);
}
use of io.servicetalk.http.api.HttpServerBuilder in project servicetalk by apple.
the class AbstractJerseyStreamingHttpServiceTest method setUp.
protected void setUp(final RouterApi api) throws Exception {
this.api = api;
HttpServerBuilder serverBuilder = HttpServers.forAddress(localAddress(0));
HttpJerseyRouterBuilder routerBuilder = new HttpJerseyRouterBuilder();
configureBuilders(serverBuilder, routerBuilder);
DefaultJerseyStreamingHttpRouter router = routerBuilder.from(application());
final Configuration config = router.configuration();
streamingJsonEnabled = getValue(config.getProperties(), config.getRuntimeType(), JSON_FEATURE, "", String.class).toLowerCase().contains("servicetalk");
HttpServerBuilder httpServerBuilder = serverBuilder.ioExecutor(serverCtx.ioExecutor()).bufferAllocator(serverCtx.bufferAllocator());
switch(api) {
case ASYNC_AGGREGATED:
serverContext = buildRouter(httpServerBuilder, toAggregated(router));
break;
case ASYNC_STREAMING:
serverContext = buildRouter(httpServerBuilder, router);
break;
case BLOCKING_AGGREGATED:
serverContext = buildRouter(httpServerBuilder, toBlocking(router));
break;
case BLOCKING_STREAMING:
serverContext = buildRouter(httpServerBuilder, toBlockingStreaming(router));
break;
default:
throw new IllegalArgumentException(api.name());
}
final HostAndPort hostAndPort = serverHostAndPort(serverContext);
httpClient = HttpClients.forSingleAddress(hostAndPort).buildStreaming();
hostHeader = hostHeader(hostAndPort);
}
use of io.servicetalk.http.api.HttpServerBuilder in project servicetalk by apple.
the class TcpFastOpenTest method requestSucceedsEvenIfTcpFastOpenNotEnabledOrSupported.
@ParameterizedTest(name = "{displayName} [{index}] protocols={0}, secure={1}, serverListenOptions={2}, clientOptions={3}")
@MethodSource("sslProviders")
void requestSucceedsEvenIfTcpFastOpenNotEnabledOrSupported(final Collection<HttpProtocol> protocols, final boolean secure, @SuppressWarnings("rawtypes") final Map<SocketOption, Object> serverListenOptions, @SuppressWarnings("rawtypes") final Map<SocketOption, Object> clientOptions) throws Exception {
assumeTcpFastOpen(clientOptions);
HttpServerBuilder serverBuilder = HttpServers.forAddress(localAddress(0)).protocols(toConfigs(protocols));
if (secure) {
serverBuilder.sslConfig(new ServerSslConfigBuilder(DefaultTestCerts::loadServerPem, DefaultTestCerts::loadServerKey).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 = newClient(serverContext, protocols, secure, clientOptions)) {
assertEquals(HttpResponseStatus.OK, client.request(client.get("/")).status());
}
}
Aggregations