use of io.servicetalk.transport.api.ConnectionObserver in project servicetalk by apple.
the class DeferredServerChannelBinder method bind.
static Single<HttpServerContext> bind(final HttpExecutionContext executionContext, final ReadOnlyHttpServerConfig config, final SocketAddress listenAddress, @Nullable final InfluencerConnectionAcceptor connectionAcceptor, final StreamingHttpService service, final boolean drainRequestPayloadBody, final boolean sniOnly) {
final ReadOnlyTcpServerConfig tcpConfig = config.tcpConfig();
assert tcpConfig.sslContext() != null;
final BiFunction<Channel, ConnectionObserver, Single<NettyConnectionContext>> channelInit = sniOnly ? (channel, connectionObserver) -> sniInitChannel(listenAddress, channel, config, executionContext, service, drainRequestPayloadBody, connectionObserver) : (channel, connectionObserver) -> alpnInitChannel(listenAddress, channel, config, executionContext, service, drainRequestPayloadBody, connectionObserver);
// In case ALPN negotiates h2, h2 connection MUST enable auto read for its Channel.
return TcpServerBinder.bind(listenAddress, tcpConfig, false, executionContext, connectionAcceptor, channelInit, serverConnection -> {
// Start processing requests on http/1.1 connection:
if (serverConnection instanceof NettyHttpServerConnection) {
((NettyHttpServerConnection) serverConnection).process(true);
}
// Nothing to do otherwise as h2 uses auto read on the parent channel
}).map(delegate -> {
LOGGER.debug("Started HTTP server with ALPN for address {}", delegate.listenAddress());
// The ServerContext returned by TcpServerBinder takes care of closing the connectionAcceptor.
return new NettyHttpServer.NettyHttpServerContext(delegate, service, executionContext);
});
}
use of io.servicetalk.transport.api.ConnectionObserver in project servicetalk by apple.
the class FlushStrategyOnServerTest method setUp.
private void setUp(final Param param) {
this.interceptor = new OutboundWriteEventsInterceptor();
this.headersFactory = DefaultHttpHeadersFactory.INSTANCE;
final StreamingHttpService service = (ctx, request, responseFactory) -> {
StreamingHttpResponse resp = responseFactory.ok();
if (request.headers().get(USE_EMPTY_RESP_BODY) == null) {
resp.payloadBody(from("Hello", "World"), appSerializerUtf8FixLen());
}
if (request.headers().get(USE_AGGREGATED_RESP) != null) {
return resp.toResponse().map(HttpResponse::toStreamingResponse);
}
return succeeded(resp);
};
final DefaultHttpExecutionContext httpExecutionContext = new DefaultHttpExecutionContext(DEFAULT_ALLOCATOR, globalExecutionContext().ioExecutor(), EXECUTOR_RULE.executor(), param.executionStrategy);
final ReadOnlyHttpServerConfig config = new HttpServerConfig().asReadOnly();
final ReadOnlyTcpServerConfig tcpReadOnly = new TcpServerConfig().asReadOnly();
try {
serverContext = TcpServerBinder.bind(localAddress(0), tcpReadOnly, true, httpExecutionContext, null, (channel, observer) -> {
final ConnectionObserver connectionObserver = config.tcpConfig().transportObserver().onNewConnection(channel.localAddress(), channel.remoteAddress());
return initChannel(channel, httpExecutionContext, config, new TcpServerChannelInitializer(tcpReadOnly, connectionObserver).andThen(channel1 -> channel1.pipeline().addLast(interceptor)), service, true, connectionObserver);
}, connection -> connection.process(true)).map(delegate -> new NettyHttpServerContext(delegate, service, httpExecutionContext)).toFuture().get();
} catch (Exception e) {
fail(e);
}
client = HttpClients.forSingleAddress(serverHostAndPort(serverContext)).protocols(h1Default()).buildBlocking();
}
Aggregations