Revert "Fix 2214 hoxton (#2285)"

This reverts commit 907119dfa3.
This commit is contained in:
Olga MaciaszekSharma
2021-07-02 19:03:05 +02:00
parent 907119dfa3
commit c87602f09e
3 changed files with 4 additions and 38 deletions

View File

@@ -44,7 +44,8 @@ import org.springframework.web.reactive.DispatcherHandler;
@AutoConfigureBefore(GatewayAutoConfiguration.class)
@ConditionalOnBean(ReactiveRedisTemplate.class)
@ConditionalOnClass({ RedisTemplate.class, DispatcherHandler.class })
@ConditionalOnProperty(name = "spring.cloud.gateway.redis.enabled", matchIfMissing = true)
@ConditionalOnProperty(name = "spring.cloud.gateway.redis.enabled",
matchIfMissing = true)
class GatewayRedisAutoConfiguration {
@Bean

View File

@@ -16,8 +16,6 @@
package org.springframework.cloud.gateway.filter.headers;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.URI;
import java.util.ArrayList;
@@ -122,17 +120,8 @@ public class ForwardedHeadersFilter implements HttpHeadersFilter, Ordered {
if (remoteAddress != null) {
// If remoteAddress is unresolved, calling getHostAddress() would cause a
// NullPointerException.
String forValue;
if (remoteAddress.isUnresolved()) {
forValue = remoteAddress.getHostName();
}
else {
InetAddress address = remoteAddress.getAddress();
forValue = remoteAddress.getAddress().getHostAddress();
if (address instanceof Inet6Address) {
forValue = "[" + forValue + "]";
}
}
String forValue = remoteAddress.isUnresolved() ? remoteAddress.getHostName()
: remoteAddress.getAddress().getHostAddress();
int port = remoteAddress.getPort();
if (port >= 0) {
forValue = forValue + ":" + port;

View File

@@ -131,30 +131,6 @@ public class ForwardedHeadersFilterTests {
.containsEntry("for", "\"10.0.0.1:80\"");
}
@Test
public void correctIPv6RemoteAddressMapping() throws UnknownHostException {
MockServerHttpRequest request = MockServerHttpRequest.get("http://localhost/get")
.remoteAddress(new InetSocketAddress(
InetAddress.getByName("2001:db8:cafe:0:0:0:0:17"), 80))
.header(HttpHeaders.HOST, "myhost").build();
ForwardedHeadersFilter filter = new ForwardedHeadersFilter();
HttpHeaders headers = filter.filter(request.getHeaders(),
MockServerWebExchange.from(request));
assertThat(headers.get(FORWARDED_HEADER)).hasSize(1);
List<Forwarded> forwardeds = ForwardedHeadersFilter
.parse(headers.get(FORWARDED_HEADER));
assertThat(forwardeds).hasSize(1);
Forwarded forwarded = forwardeds.get(0);
assertThat(forwarded.getValues()).containsEntry("for",
"\"[2001:db8:cafe:0:0:0:0:17]:80\"");
}
@Test
public void unresolvedRemoteAddressFallsBackToHostName() throws UnknownHostException {
MockServerHttpRequest request = MockServerHttpRequest.get("http://localhost/get")