diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncServerBootstrap.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncServerBootstrap.java index 17ec7608a..7c9171574 100644 --- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncServerBootstrap.java +++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncServerBootstrap.java @@ -28,6 +28,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.function.BiFunction; import org.apache.hc.core5.function.Callback; import org.apache.hc.core5.function.Decorator; @@ -95,6 +96,7 @@ public class AsyncServerBootstrap { private IOSessionListener sessionListener; private Http1StreamListener streamListener; private IOReactorMetricsListener threadPoolListener; + private BiFunction authorityResolver = RequestRouter.IGNORE_PORT_AUTHORITY_RESOLVER; private AsyncServerBootstrap() { this.routeEntries = new ArrayList<>(); @@ -280,6 +282,17 @@ public final AsyncServerBootstrap setStreamListener(final Http1StreamListener st return this; } + /** + * Sets authority resolver to be used when creating the {@link RequestRouter}. + * + * @return this instance. + * @since 5.4 + */ + public final AsyncServerBootstrap setAuthorityResolver(final BiFunction authorityResolver) { + this.authorityResolver = authorityResolver; + return this; + } + /** * Registers the given {@link AsyncServerExchangeHandler} {@link Supplier} as a default handler for URIs * matching the given pattern. @@ -453,7 +466,7 @@ public HttpAsyncServer create() { requestRouterCopy = RequestRouter.create( new URIAuthority(actualCanonicalHostName), UriPatternType.URI_PATTERN, routeEntries, - RequestRouter.IGNORE_PORT_AUTHORITY_RESOLVER, + this.authorityResolver, requestRouter); } } diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/ServerBootstrap.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/ServerBootstrap.java index da887dbf1..2f9ffcc65 100644 --- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/ServerBootstrap.java +++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/ServerBootstrap.java @@ -29,6 +29,7 @@ import java.net.InetAddress; import java.util.ArrayList; import java.util.List; +import java.util.function.BiFunction; import javax.net.ServerSocketFactory; import javax.net.ssl.SSLContext; @@ -98,6 +99,7 @@ public class ServerBootstrap { private HttpConnectionFactory connectionFactory; private ExceptionListener exceptionListener; private Http1StreamListener streamListener; + private BiFunction authorityResolver = RequestRouter.IGNORE_PORT_AUTHORITY_RESOLVER; private ServerBootstrap() { this.routeEntries = new ArrayList<>(); @@ -294,6 +296,17 @@ public final ServerBootstrap setStreamListener(final Http1StreamListener streamL return this; } + /** + * Sets authority resolver to be used when creating the {@link RequestRouter}. + * + * @return this instance. + * @since 5.4 + */ + public final ServerBootstrap setAuthorityResolver(final BiFunction authorityResolver) { + this.authorityResolver = authorityResolver; + return this; + } + /** * Adds the filter before the filter with the given name. */ @@ -365,7 +378,7 @@ public HttpServer create() { new URIAuthority(actualCanonicalHostName), UriPatternType.URI_PATTERN, routeEntries, - RequestRouter.IGNORE_PORT_AUTHORITY_RESOLVER, + this.authorityResolver, requestRouter); } }