From 64a579d68d3be975a72e639c7cc123a756e21a28 Mon Sep 17 00:00:00 2001 From: Spencer Gibb Date: Tue, 14 Jan 2020 13:53:19 -0500 Subject: [PATCH] Adds max response header configuration. fixes gh-1457 --- .../gateway/config/GatewayAutoConfiguration.java | 9 ++++++++- .../gateway/config/HttpClientProperties.java | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java index d05ea769..2176eb3d 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java @@ -572,7 +572,14 @@ public class GatewayAutoConfiguration { } HttpClient httpClient = HttpClient.create(connectionProvider) - .tcpConfiguration(tcpClient -> { + .httpResponseDecoder(spec -> { + if (properties.getMaxHeaderSize() != null) { + // cast to int is ok, since @Max is Integer.MAX_VALUE + spec.maxHeaderSize( + (int) properties.getMaxHeaderSize().toBytes()); + } + return spec; + }).tcpConfiguration(tcpClient -> { if (properties.getConnectTimeout() != null) { tcpClient = tcpClient.option( diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/config/HttpClientProperties.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/config/HttpClientProperties.java index e37f9865..d24ecfdb 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/config/HttpClientProperties.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/config/HttpClientProperties.java @@ -27,6 +27,8 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; +import javax.validation.constraints.Max; + import reactor.netty.resources.ConnectionProvider; import reactor.netty.tcp.SslProvider; @@ -35,6 +37,7 @@ import org.springframework.boot.context.properties.DeprecatedConfigurationProper import org.springframework.boot.web.server.WebServerException; import org.springframework.core.style.ToStringCreator; import org.springframework.util.ResourceUtils; +import org.springframework.util.unit.DataSize; /** * Configuration properties for the Netty {@link reactor.netty.http.client.HttpClient}. @@ -48,6 +51,9 @@ public class HttpClientProperties { /** The response timeout. */ private Duration responseTimeout; + /** The max response header size. */ + private DataSize maxHeaderSize; + /** Pool configuration for Netty HttpClient. */ private Pool pool = new Pool(); @@ -76,6 +82,15 @@ public class HttpClientProperties { this.responseTimeout = responseTimeout; } + @Max(Integer.MAX_VALUE) + public DataSize getMaxHeaderSize() { + return maxHeaderSize; + } + + public void setMaxHeaderSize(DataSize maxHeaderSize) { + this.maxHeaderSize = maxHeaderSize; + } + public Pool getPool() { return pool; } @@ -114,6 +129,7 @@ public class HttpClientProperties { return new ToStringCreator(this) .append("connectTimeout", connectTimeout) .append("responseTimeout", responseTimeout) + .append("maxHeaderSize", maxHeaderSize) .append("pool", pool) .append("proxy", proxy) .append("ssl", ssl)