in httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncServerBootstrap.java [438:522]
public HttpAsyncServer create() {
final String actualCanonicalHostName = canonicalHostName != null ? canonicalHostName : InetAddressUtils.getCanonicalLocalHostName();
final HttpRequestMapper<Supplier<AsyncServerExchangeHandler>> requestRouterCopy;
if (lookupRegistry != null && requestRouter == null) {
final org.apache.hc.core5.http.protocol.RequestHandlerRegistry<Supplier<AsyncServerExchangeHandler>> handlerRegistry = new org.apache.hc.core5.http.protocol.RequestHandlerRegistry<>(
actualCanonicalHostName,
() -> lookupRegistry != null ? lookupRegistry : new org.apache.hc.core5.http.protocol.UriPatternMatcher<>());
for (final RequestRouter.Entry<Supplier<AsyncServerExchangeHandler>> entry: routeEntries) {
handlerRegistry.register(entry.uriAuthority != null ? entry.uriAuthority.getHostName() : null, entry.route.pattern, entry.route.handler);
}
requestRouterCopy = handlerRegistry;
} else {
if (routeEntries.isEmpty()) {
requestRouterCopy = requestRouter;
} else {
requestRouterCopy = RequestRouter.create(
new URIAuthority(actualCanonicalHostName),
UriPatternType.URI_PATTERN, routeEntries,
RequestRouter.IGNORE_PORT_AUTHORITY_RESOLVER,
requestRouter);
}
}
final HandlerFactory<AsyncServerExchangeHandler> handlerFactory;
if (!filters.isEmpty()) {
final NamedElementChain<AsyncFilterHandler> filterChainDefinition = new NamedElementChain<>();
filterChainDefinition.addLast(
new TerminalAsyncServerFilter(new DefaultAsyncResponseExchangeHandlerFactory(requestRouterCopy)),
StandardFilter.MAIN_HANDLER.name());
filterChainDefinition.addFirst(
new AsyncServerExpectationFilter(),
StandardFilter.EXPECT_CONTINUE.name());
for (final FilterEntry<AsyncFilterHandler> entry: filters) {
switch (entry.position) {
case AFTER:
filterChainDefinition.addAfter(entry.existing, entry.filterHandler, entry.name);
break;
case BEFORE:
filterChainDefinition.addBefore(entry.existing, entry.filterHandler, entry.name);
break;
case REPLACE:
filterChainDefinition.replace(entry.existing, entry.filterHandler);
break;
case FIRST:
filterChainDefinition.addFirst(entry.filterHandler, entry.name);
break;
case LAST:
// Don't add last, after TerminalAsyncServerFilter, as that does not delegate to the chain
// Instead, add the filter just before it, making it effectively the last filter
filterChainDefinition.addBefore(StandardFilter.MAIN_HANDLER.name(), entry.filterHandler, entry.name);
break;
}
}
NamedElementChain<AsyncFilterHandler>.Node current = filterChainDefinition.getLast();
AsyncServerFilterChainElement execChain = null;
while (current != null) {
execChain = new AsyncServerFilterChainElement(current.getValue(), execChain);
current = current.getPrevious();
}
handlerFactory = new AsyncServerFilterChainExchangeHandlerFactory(execChain, exceptionCallback);
} else {
handlerFactory = new DefaultAsyncResponseExchangeHandlerFactory(requestRouterCopy, handler -> new BasicAsyncServerExpectationDecorator(handler, exceptionCallback));
}
final ServerHttp1StreamDuplexerFactory streamHandlerFactory = new ServerHttp1StreamDuplexerFactory(
httpProcessor != null ? httpProcessor : HttpProcessors.server(),
handlerFactory,
http1Config,
charCodingConfig != null ? charCodingConfig : CharCodingConfig.DEFAULT,
connStrategy != null ? connStrategy : DefaultConnectionReuseStrategy.INSTANCE,
new DefaultHttpRequestParserFactory(http1Config),
new DefaultHttpResponseWriterFactory(http1Config),
DefaultContentLengthStrategy.INSTANCE,
DefaultContentLengthStrategy.INSTANCE,
streamListener,
exceptionCallback);
final IOEventHandlerFactory ioEventHandlerFactory = new ServerHttp1IOEventHandlerFactory(
streamHandlerFactory,
tlsStrategy,
handshakeTimeout);
return new HttpAsyncServer(ioEventHandlerFactory, ioReactorConfig, ioSessionDecorator, exceptionCallback,
sessionListener, threadPoolListener, null, null);
}