use of io.servicetalk.http.netty.NettyHttpServer.NettyHttpServerConnection 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.http.netty.NettyHttpServer.NettyHttpServerConnection in project servicetalk by apple.
the class ServerGracefulConnectionClosureHandlingTest method setUp.
@BeforeEach
void setUp() throws Exception {
AtomicReference<Runnable> serverClose = new AtomicReference<>();
serverContext = forAddress(localAddress(0)).ioExecutor(SERVER_CTX.ioExecutor()).executor(SERVER_CTX.executor()).executionStrategy(offloadNever()).appendConnectionAcceptorFilter(original -> new DelegatingConnectionAcceptor(original) {
@Override
public Completable accept(final ConnectionContext context) {
((NettyHttpServerConnection) context).onClosing().whenFinally(serverConnectionClosing::countDown).subscribe();
context.onClose().whenFinally(serverConnectionClosed::countDown).subscribe();
return completed();
}
}).listenStreamingAndAwait((ctx, request, responseFactory) -> succeeded(responseFactory.ok().addHeader(CONTENT_LENGTH, valueOf(RESPONSE_CONTENT.length())).payloadBody(request.payloadBody().ignoreElements().concat(from(RESPONSE_CONTENT)), RAW_STRING_SERIALIZER).transformMessageBody(payload -> payload.whenFinally(serverClose.get()))));
serverContext.onClose().whenFinally(serverContextClosed::countDown).subscribe();
serverClose.set(() -> serverContext.closeAsyncGracefully().subscribe());
serverAddress = (InetSocketAddress) serverContext.listenAddress();
}
Aggregations