diff --git a/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/NettyRoutingFilter.java b/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/NettyRoutingFilter.java index 0e705edf..5541a03b 100644 --- a/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/NettyRoutingFilter.java +++ b/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/NettyRoutingFilter.java @@ -112,7 +112,7 @@ public class NettyRoutingFilter implements GlobalFilter, Ordered { URI requestUrl = exchange.getRequiredAttribute(GATEWAY_REQUEST_URL_ATTR); String scheme = requestUrl.getScheme(); - if (isAlreadyRouted(exchange) || (!"http".equals(scheme) && !"https".equals(scheme))) { + if (isAlreadyRouted(exchange) || (!"http".equalsIgnoreCase(scheme) && !"https".equalsIgnoreCase(scheme))) { return chain.filter(exchange); } setAlreadyRouted(exchange); diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/NettyRoutingFilterTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/NettyRoutingFilterTests.java index 9ce56a89..3b5c7f0a 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/NettyRoutingFilterTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/NettyRoutingFilterTests.java @@ -17,9 +17,14 @@ package org.springframework.cloud.gateway.filter; import org.hamcrest.Matchers; +import org.junit.Assert; +import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; +import reactor.core.publisher.Mono; +import reactor.netty.DisposableServer; +import reactor.netty.http.server.HttpServer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringBootConfiguration; @@ -27,20 +32,29 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.cloud.gateway.route.RouteLocator; import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder; +import org.springframework.cloud.gateway.test.BaseWebClientTests; import org.springframework.cloud.gateway.test.PermitAllSecurityConfiguration; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Import; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.reactive.server.WebTestClient; +import org.springframework.util.SocketUtils; @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -public class NettyRoutingFilterTests { +public class NettyRoutingFilterTests extends BaseWebClientTests { + + private static int port; @Autowired private ApplicationContext context; + @BeforeClass + public static void beforeAll() { + port = SocketUtils.findAvailableTcpPort(); + } + @Test @Ignore public void mockServerWorks() { @@ -48,6 +62,30 @@ public class NettyRoutingFilterTests { client.get().uri("/mockexample").exchange().expectStatus().value(Matchers.lessThan(500)); } + @Test // gh-2207 + public void testCaseInsensitiveScheme() { + DisposableServer server = HttpServer + .create().port(port).host( + "127.0.0.1") + .route(routes -> routes.get("/issue", (request, response) -> response + .sendString(Mono.just("issue2207")))) + .bindNow(); + + try { + testClient.get().uri("/issue").exchange().expectStatus().isOk().expectBody() + .consumeWith(entityExchangeResult -> { + Assert.assertNotNull(entityExchangeResult); + Assert.assertNotNull(entityExchangeResult.getResponseBody()); + String content = new String( + entityExchangeResult.getResponseBody()); + Assert.assertEquals("issue2207", content); + }); + } + finally { + server.disposeNow(); + } + } + @SpringBootConfiguration @EnableAutoConfiguration @Import(PermitAllSecurityConfiguration.class) @@ -57,7 +95,7 @@ public class NettyRoutingFilterTests { public RouteLocator routes(RouteLocatorBuilder builder) { return builder.routes() .route(p -> p.path("/mockexample").filters(f -> f.prefixPath("/httpbin")).uri("http://example.com")) - .build(); + .route(p -> p.path("/issue").uri("HTTP://127.0.0.1:" + port)).build(); } }