Merge branch '2.2.x'

This commit is contained in:
spencergibb
2021-05-24 11:20:32 -04:00
2 changed files with 41 additions and 3 deletions

View File

@@ -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);

View File

@@ -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();
}
}