Fixes for gateway routes on management port.

Uses the LocalAddress to check against management port because request.getURI().getPort() can be set by the host header "myhost:8888", for example.

Fixes gh-2870
This commit is contained in:
spencergibb
2023-02-21 11:18:31 -05:00
parent 180a052c76
commit a2ef4895a4
2 changed files with 8 additions and 1 deletions

View File

@@ -77,7 +77,7 @@ public class RoutePredicateHandlerMapping extends AbstractHandlerMapping {
protected Mono<?> getHandlerInternal(ServerWebExchange exchange) {
// don't handle requests on management port if set and different than server port
if (this.managementPortType == DIFFERENT && this.managementPort != null
&& exchange.getRequest().getURI().getPort() == this.managementPort) {
&& exchange.getRequest().getLocalAddress().getPort() == this.managementPort) {
return Mono.empty();
}
exchange.getAttributes().put(GATEWAY_HANDLER_MAPPER_ATTR, getSimpleName());

View File

@@ -60,6 +60,13 @@ public class RoutePredicateHandlerMappingIntegrationTests extends BaseWebClientT
.expectStatus().isNotFound();
}
@Test
public void requestsToManagementPortAndHostHeaderReturn404() {
String host = "example.com:8888";
testClient.mutate().baseUrl("http://localhost:" + managementPort).build().get().uri("/get").header("host", host)
.exchange().expectStatus().isNotFound();
}
@Test
public void andNotWorksWithMissingParameter() {
testClient.get().uri("/andnotquery").exchange().expectBody(String.class).isEqualTo("notsupplied");