Avoid direct URL construction.
Fixes gh-2783
This commit is contained in:
@@ -18,8 +18,6 @@ package org.springframework.cloud.gateway.filter.factory;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@@ -71,9 +69,11 @@ public class RequestHeaderToRequestUriGatewayFilterFactory
|
||||
String requestUrl = exchange.getRequest().getHeaders().getFirst(config.getName());
|
||||
return Optional.ofNullable(requestUrl).map(url -> {
|
||||
try {
|
||||
return new URL(url).toURI();
|
||||
URI uri = URI.create(url);
|
||||
uri.toURL(); // validate url
|
||||
return uri;
|
||||
}
|
||||
catch (MalformedURLException | URISyntaxException e) {
|
||||
catch (IllegalArgumentException | MalformedURLException e) {
|
||||
log.info("Request url is invalid : url={}, error={}", requestUrl, e.getMessage());
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.net.URI;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
@@ -48,7 +47,6 @@ public class RequestHeaderToRequestUriGatewayFilterFactoryIntegrationTests exten
|
||||
int port;
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
public void changeUriWorkWithProperties() {
|
||||
testClient.get().uri("/").header("Host", "www.changeuri.org")
|
||||
.header("X-CF-Forwarded-Url", "http://localhost:" + port + "/actuator/health").exchange()
|
||||
@@ -56,7 +54,6 @@ public class RequestHeaderToRequestUriGatewayFilterFactoryIntegrationTests exten
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
public void changeUriWorkWithDsl() {
|
||||
testClient.get().uri("/").header("Host", "www.changeuri.org")
|
||||
.header("X-Next-Url", "http://localhost:" + port + "/actuator/health").exchange()
|
||||
|
||||
Reference in New Issue
Block a user