Updates to*Case() to use Locale.ROOT
This commit is contained in:
@@ -31,6 +31,7 @@ import java.util.Enumeration;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.Vector;
|
||||
import java.util.function.Function;
|
||||
@@ -234,7 +235,7 @@ public class ProxyExchange<T> {
|
||||
|
||||
this.excluded.clear();
|
||||
for (String name : names) {
|
||||
this.excluded.add(name.toLowerCase());
|
||||
this.excluded.add(name.toLowerCase(Locale.ROOT));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@@ -384,7 +385,7 @@ public class ProxyExchange<T> {
|
||||
private Set<String> filterHeaderKeys(Collection<String> headerNames) {
|
||||
final Set<String> excludedHeaders = this.excluded != null ? this.excluded : Collections.emptySet();
|
||||
return headerNames.stream()
|
||||
.filter(header -> !excludedHeaders.contains(header.toLowerCase()))
|
||||
.filter(header -> !excludedHeaders.contains(header.toLowerCase(Locale.ROOT)))
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
@@ -101,7 +102,7 @@ public class ProxyExchangeArgumentResolver implements HandlerMethodArgumentResol
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
while (headerNames.hasMoreElements()) {
|
||||
String header = headerNames.nextElement();
|
||||
if (this.autoForwardedHeaders.contains(header.toLowerCase())) {
|
||||
if (this.autoForwardedHeaders.contains(header.toLowerCase(Locale.ROOT))) {
|
||||
headers.addAll(header, Collections.list(nativeRequest.getHeaders(header)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.cloud.gateway.sample;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -77,7 +78,7 @@ public class GatewaySampleApplication {
|
||||
.addResponseHeader("X-TestHeader", "rewrite_request")
|
||||
.modifyRequestBody(String.class, Hello.class, MediaType.APPLICATION_JSON_VALUE,
|
||||
(exchange, s) -> {
|
||||
return Mono.just(new Hello(s.toUpperCase()));
|
||||
return Mono.just(new Hello(s.toUpperCase(Locale.ROOT)));
|
||||
})
|
||||
).uri(uri)
|
||||
)
|
||||
@@ -86,7 +87,7 @@ public class GatewaySampleApplication {
|
||||
.addResponseHeader("X-TestHeader", "rewrite_request_upper")
|
||||
.modifyRequestBody(String.class, String.class,
|
||||
(exchange, s) -> {
|
||||
return Mono.just(s.toUpperCase() + s.toUpperCase());
|
||||
return Mono.just(s.toUpperCase(Locale.ROOT) + s.toUpperCase(Locale.ROOT));
|
||||
})
|
||||
).uri(uri)
|
||||
)
|
||||
@@ -95,7 +96,7 @@ public class GatewaySampleApplication {
|
||||
.addResponseHeader("X-TestHeader", "rewrite_response_upper")
|
||||
.modifyResponseBody(String.class, String.class,
|
||||
(exchange, s) -> {
|
||||
return Mono.just(s.toUpperCase());
|
||||
return Mono.just(s.toUpperCase(Locale.ROOT));
|
||||
})
|
||||
).uri(uri)
|
||||
)
|
||||
@@ -107,7 +108,7 @@ public class GatewaySampleApplication {
|
||||
if (s == null) {
|
||||
return Mono.just("emptybody");
|
||||
}
|
||||
return Mono.just(s.toUpperCase());
|
||||
return Mono.just(s.toUpperCase(Locale.ROOT));
|
||||
})
|
||||
|
||||
).uri(uri)
|
||||
@@ -120,7 +121,7 @@ public class GatewaySampleApplication {
|
||||
if (s == null) {
|
||||
return Mono.error(new IllegalArgumentException("this should not happen"));
|
||||
}
|
||||
return Mono.just(s.toUpperCase());
|
||||
return Mono.just(s.toUpperCase(Locale.ROOT));
|
||||
})
|
||||
).uri(uri)
|
||||
)
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.cloud.gateway.server.mvc.common;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.springframework.core.style.ToStringCreator;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.HttpStatusCode;
|
||||
@@ -36,7 +38,7 @@ public class HttpStatusHolder {
|
||||
public static HttpStatusHolder valueOf(String status) {
|
||||
HttpStatusCode httpStatus;
|
||||
try {
|
||||
httpStatus = HttpStatus.valueOf(status.toUpperCase());
|
||||
httpStatus = HttpStatus.valueOf(status.toUpperCase(Locale.ROOT));
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
httpStatus = null;
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
@@ -163,13 +164,13 @@ public class RouterFunctionHolderFactory {
|
||||
String scheme = routeProperties.getUri().getScheme();
|
||||
Map<String, Object> handlerArgs = new HashMap<>();
|
||||
Optional<NormalizedOperationMethod> handlerOperationMethod = findOperation(handlerOperations,
|
||||
scheme.toLowerCase(), handlerArgs);
|
||||
scheme.toLowerCase(Locale.ROOT), handlerArgs);
|
||||
if (handlerOperationMethod.isEmpty()) {
|
||||
// single RouteProperties param
|
||||
handlerArgs.clear();
|
||||
String routePropsKey = StringUtils.uncapitalize(RouteProperties.class.getSimpleName());
|
||||
handlerArgs.put(routePropsKey, routeProperties);
|
||||
handlerOperationMethod = findOperation(handlerOperations, scheme.toLowerCase(), handlerArgs);
|
||||
handlerOperationMethod = findOperation(handlerOperations, scheme.toLowerCase(Locale.ROOT), handlerArgs);
|
||||
if (handlerOperationMethod.isEmpty()) {
|
||||
throw new IllegalStateException("Unable to find HandlerFunction for scheme: " + scheme);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.springframework.cloud.gateway.server.mvc.filter;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -55,7 +56,7 @@ public class RemoveHopByHopRequestHeadersFilter implements RequestHttpHeadersFil
|
||||
HttpHeaders filtered = new HttpHeaders();
|
||||
|
||||
for (Map.Entry<String, List<String>> entry : input.entrySet()) {
|
||||
if (!headersToRemove.contains(entry.getKey().toLowerCase())) {
|
||||
if (!headersToRemove.contains(entry.getKey().toLowerCase(Locale.ROOT))) {
|
||||
filtered.addAll(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.time.Duration;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
@@ -1533,12 +1534,12 @@ public class ServerMvcIntegrationTests {
|
||||
return route("testmodifyrequestbodystring")
|
||||
.POST("/post", host("**.modifyrequestbodystring.org"), http())
|
||||
.before(new HttpbinUriResolver())
|
||||
.before(modifyRequestBody(String.class, String.class, null, (request, s) -> s.toUpperCase() + s.toUpperCase()))
|
||||
.before(modifyRequestBody(String.class, String.class, null, (request, s) -> s.toUpperCase(Locale.ROOT) + s.toUpperCase(Locale.ROOT)))
|
||||
.build().and(
|
||||
route("testmodifyrequestbodyobject")
|
||||
.POST("/post", host("**.modifyrequestbodyobject.org"), http())
|
||||
.before(new HttpbinUriResolver())
|
||||
.before(modifyRequestBody(String.class, Hello.class, MediaType.APPLICATION_JSON_VALUE, (request, s) -> new Hello(s.toUpperCase())))
|
||||
.before(modifyRequestBody(String.class, Hello.class, MediaType.APPLICATION_JSON_VALUE, (request, s) -> new Hello(s.toUpperCase(Locale.ROOT))))
|
||||
.build());
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.cloud.gateway.server.mvc;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -79,7 +80,7 @@ public class VanillaRouterFunctionTests {
|
||||
// @formatter:off
|
||||
return RouterFunctions.route()
|
||||
.POST("/anything/routerfunctionsroute", host("**.routerfunctionsroute.org"), http())
|
||||
.before(modifyRequestBody(String.class, String.class, null, (request, s) -> s.toUpperCase()))
|
||||
.before(modifyRequestBody(String.class, String.class, null, (request, s) -> s.toUpperCase(Locale.ROOT)))
|
||||
.before(new HttpbinUriResolver())
|
||||
.build();
|
||||
// @formatter:on
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.springframework.cloud.gateway.discovery;
|
||||
import java.net.URI;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@@ -170,7 +171,7 @@ public class DiscoveryClientRouteDefinitionLocator implements RouteDefinitionLoc
|
||||
@Override
|
||||
public String getServiceId() {
|
||||
if (properties.isLowerCaseServiceId()) {
|
||||
return delegate.getServiceId().toLowerCase();
|
||||
return delegate.getServiceId().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
return delegate.getServiceId();
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
@@ -79,7 +80,7 @@ public class WebsocketRoutingFilter implements GlobalFilter, Ordered {
|
||||
|
||||
/* for testing */
|
||||
static String convertHttpToWs(String scheme) {
|
||||
scheme = scheme.toLowerCase();
|
||||
scheme = scheme.toLowerCase(Locale.ROOT);
|
||||
return "http".equals(scheme) ? "ws" : "https".equals(scheme) ? "wss" : scheme;
|
||||
}
|
||||
|
||||
@@ -143,7 +144,7 @@ public class WebsocketRoutingFilter implements GlobalFilter, Ordered {
|
||||
headersFilters.add((headers, exchange) -> {
|
||||
HttpHeaders filtered = new HttpHeaders();
|
||||
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
|
||||
if (!entry.getKey().toLowerCase().startsWith("sec-websocket")) {
|
||||
if (!entry.getKey().toLowerCase(Locale.ROOT).startsWith("sec-websocket")) {
|
||||
filtered.addAll(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
@@ -157,7 +158,7 @@ public class WebsocketRoutingFilter implements GlobalFilter, Ordered {
|
||||
static void changeSchemeIfIsWebSocketUpgrade(ServerWebExchange exchange) {
|
||||
// Check the Upgrade
|
||||
URI requestUrl = exchange.getRequiredAttribute(GATEWAY_REQUEST_URL_ATTR);
|
||||
String scheme = requestUrl.getScheme().toLowerCase();
|
||||
String scheme = requestUrl.getScheme().toLowerCase(Locale.ROOT);
|
||||
String upgrade = exchange.getRequest().getHeaders().getUpgrade();
|
||||
// change the scheme if the socket client send a "http" or "https"
|
||||
if ("WebSocket".equalsIgnoreCase(upgrade) && ("http".equals(scheme) || "https".equals(scheme))) {
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.cloud.gateway.filter.factory;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@@ -136,7 +137,7 @@ public class SecureHeadersGatewayFilterFactory
|
||||
}
|
||||
|
||||
private boolean isEnabled(List<String> disabledHeaders, String header) {
|
||||
return !disabledHeaders.contains(header.toLowerCase());
|
||||
return !disabledHeaders.contains(header.toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
public static class Config {
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.springframework.cloud.gateway.filter.headers;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -74,7 +75,7 @@ public class RemoveHopByHopHeadersFilter implements HttpHeadersFilter, Ordered {
|
||||
headersToRemove.addAll(connectionOptions);
|
||||
|
||||
for (Map.Entry<String, List<String>> entry : originalHeaders.entrySet()) {
|
||||
if (!headersToRemove.contains(entry.getKey().toLowerCase())) {
|
||||
if (!headersToRemove.contains(entry.getKey().toLowerCase(Locale.ROOT))) {
|
||||
filtered.addAll(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.cloud.gateway.support;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -79,7 +80,7 @@ public final class NameUtils {
|
||||
matcher.appendReplacement(stringBuffer, matcher.group(1));
|
||||
}
|
||||
}
|
||||
return stringBuffer.toString().toLowerCase();
|
||||
return stringBuffer.toString().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
private static String removeGarbage(String s) {
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.net.URI;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
@@ -268,7 +269,7 @@ public final class ServerWebExchangeUtils {
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
// try the enum string
|
||||
httpStatus = HttpStatus.valueOf(statusString.toUpperCase());
|
||||
httpStatus = HttpStatus.valueOf(statusString.toUpperCase(Locale.ROOT));
|
||||
}
|
||||
return httpStatus;
|
||||
}
|
||||
|
||||
@@ -48,9 +48,9 @@ import static org.springframework.cloud.gateway.handler.predicate.RoutePredicate
|
||||
"spring.cloud.gateway.discovery.locator.lower-case-service-id=true"
|
||||
/*
|
||||
* "spring.cloud.gateway.discovery.locator.predicates[0].name=Path",
|
||||
* "spring.cloud.gateway.discovery.locator.predicates[0].args[pattern]='/'+serviceId.toLowerCase()+'/**'",
|
||||
* "spring.cloud.gateway.discovery.locator.predicates[0].args[pattern]='/'+serviceId.toLowerCase(Locale.ROOT)+'/**'",
|
||||
* "spring.cloud.gateway.discovery.locator.filters[0].name=RewritePath",
|
||||
* "spring.cloud.gateway.discovery.locator.filters[0].args[regexp]='/' + serviceId.toLowerCase() + '/(?<remaining>.*)'"
|
||||
* "spring.cloud.gateway.discovery.locator.filters[0].args[regexp]='/' + serviceId.toLowerCase(Locale.ROOT) + '/(?<remaining>.*)'"
|
||||
* ,
|
||||
* "spring.cloud.gateway.discovery.locator.filters[0].args[replacement]='/$\\\\{remaining}'",
|
||||
*/
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.cloud.gateway.filter.factory.rewrite;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@@ -134,7 +136,7 @@ public class ModifyRequestBodyGatewayFilterFactoryTests extends BaseWebClientTes
|
||||
if (body == null) {
|
||||
return Mono.just("modifyrequest");
|
||||
}
|
||||
return Mono.just(body.toUpperCase());
|
||||
return Mono.just(body.toUpperCase(Locale.ROOT));
|
||||
}))
|
||||
.uri(uri))
|
||||
.route("test_modify_request_body_to_large",
|
||||
@@ -152,7 +154,7 @@ public class ModifyRequestBodyGatewayFilterFactoryTests extends BaseWebClientTes
|
||||
.filters(f -> f.modifyRequestBody(new ParameterizedTypeReference<String>() {
|
||||
}, new ParameterizedTypeReference<String>() {
|
||||
}, (swe, body) -> {
|
||||
return Mono.just(body.replaceAll(" ", "_").toUpperCase());
|
||||
return Mono.just(body.replaceAll(" ", "_").toUpperCase(Locale.ROOT));
|
||||
}))
|
||||
.uri(uri))
|
||||
.build();
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.springframework.cloud.gateway.filter.headers;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -50,7 +51,7 @@ public class RemoveHopByHopHeadersFilterTests {
|
||||
public void caseInsensitive() {
|
||||
MockServerHttpRequest.BaseBuilder<?> builder = MockServerHttpRequest.get("http://localhost/get");
|
||||
|
||||
HEADERS_REMOVED_ON_REQUEST.forEach(header -> builder.header(header.toLowerCase(), header + "1"));
|
||||
HEADERS_REMOVED_ON_REQUEST.forEach(header -> builder.header(header.toLowerCase(Locale.ROOT), header + "1"));
|
||||
|
||||
testFilter(MockServerWebExchange.from(builder));
|
||||
}
|
||||
@@ -60,7 +61,7 @@ public class RemoveHopByHopHeadersFilterTests {
|
||||
MockServerHttpRequest.BaseBuilder<?> builder = MockServerHttpRequest.get("http://localhost/get");
|
||||
|
||||
HEADERS_REMOVED_ON_REQUEST
|
||||
.forEach(header -> builder.header(StringUtils.capitalize(header.toLowerCase()), header + "1"));
|
||||
.forEach(header -> builder.header(StringUtils.capitalize(header.toLowerCase(Locale.ROOT)), header + "1"));
|
||||
|
||||
LinkedHashSet<String> customHeaders = new LinkedHashSet<>();
|
||||
HEADERS_REMOVED_ON_REQUEST.forEach(header -> {
|
||||
@@ -78,7 +79,7 @@ public class RemoveHopByHopHeadersFilterTests {
|
||||
|
||||
String arbitraryConnectionOption = "xyz";
|
||||
assumeThat(HEADERS_REMOVED_ON_REQUEST).doesNotContain(arbitraryConnectionOption);
|
||||
builder.header(HttpHeaders.CONNECTION, "upgrade", "keep-alive", arbitraryConnectionOption.toUpperCase());
|
||||
builder.header(HttpHeaders.CONNECTION, "upgrade", "keep-alive", arbitraryConnectionOption.toUpperCase(Locale.ROOT));
|
||||
builder.header(HttpHeaders.UPGRADE, "WebSocket");
|
||||
builder.header("Keep-Alive", "timeout=5");
|
||||
builder.header(arbitraryConnectionOption, "");
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.net.URISyntaxException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -221,7 +222,7 @@ public class ProxyExchange<T> {
|
||||
|
||||
this.excluded.clear();
|
||||
for (String name : names) {
|
||||
this.excluded.add(name.toLowerCase());
|
||||
this.excluded.add(name.toLowerCase(Locale.ROOT));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@@ -407,7 +408,7 @@ public class ProxyExchange<T> {
|
||||
final Set<String> excludedHeaders = this.excluded != null ? this.excluded : Collections.emptySet();
|
||||
return headers.keySet()
|
||||
.stream()
|
||||
.filter(header -> !excludedHeaders.contains(header.toLowerCase()))
|
||||
.filter(header -> !excludedHeaders.contains(header.toLowerCase(Locale.ROOT)))
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user