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:
@@ -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());
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user