Polish "Align max HTTP header size configuration"
Closes gh-14234
This commit is contained in:
parent
dbbb378650
commit
8771b34c15
|
@ -29,6 +29,7 @@ import java.util.Map;
|
|||
import java.util.TimeZone;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
|
||||
import org.springframework.boot.context.properties.NestedConfigurationProperty;
|
||||
import org.springframework.boot.convert.DurationUnit;
|
||||
import org.springframework.boot.web.server.Compression;
|
||||
|
@ -84,7 +85,7 @@ public class ServerProperties {
|
|||
/**
|
||||
* Maximum size of the HTTP message header.
|
||||
*/
|
||||
private DataSize maxHttpHeaderSize = DataSize.ofKiloBytes(8L);
|
||||
private DataSize maxHttpHeaderSize = DataSize.ofKiloBytes(8);
|
||||
|
||||
/**
|
||||
* Time that connectors wait for another HTTP request before closing the connection.
|
||||
|
@ -328,9 +329,7 @@ public class ServerProperties {
|
|||
|
||||
/**
|
||||
* Maximum size, in bytes, of the HTTP message header.
|
||||
* @deprecated since 2.1.0 in favor of {@link ServerProperties#maxHttpHeaderSize}
|
||||
*/
|
||||
@Deprecated
|
||||
private int maxHttpHeaderSize = 0;
|
||||
|
||||
/**
|
||||
|
@ -496,10 +495,17 @@ public class ServerProperties {
|
|||
this.maxConnections = maxConnections;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@DeprecatedConfigurationProperty(replacement = "server.max-http-header-size")
|
||||
public int getMaxHttpHeaderSize() {
|
||||
return this.maxHttpHeaderSize;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setMaxHttpHeaderSize(int maxHttpHeaderSize) {
|
||||
this.maxHttpHeaderSize = maxHttpHeaderSize;
|
||||
}
|
||||
|
||||
public DataSize getMaxSwallowSize() {
|
||||
return this.maxSwallowSize;
|
||||
}
|
||||
|
@ -508,10 +514,6 @@ public class ServerProperties {
|
|||
this.maxSwallowSize = maxSwallowSize;
|
||||
}
|
||||
|
||||
public void setMaxHttpHeaderSize(int maxHttpHeaderSize) {
|
||||
this.maxHttpHeaderSize = maxHttpHeaderSize;
|
||||
}
|
||||
|
||||
public int getAcceptCount() {
|
||||
return this.acceptCount;
|
||||
}
|
||||
|
|
|
@ -116,6 +116,7 @@ public class TomcatWebServerFactoryCustomizer implements
|
|||
return value > 0;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private DataSize determineMaxHttpHeaderSize() {
|
||||
return isPositive(this.serverProperties.getTomcat().getMaxHttpHeaderSize())
|
||||
? DataSize
|
||||
|
|
|
@ -136,9 +136,16 @@ public class ServerPropertiesTests {
|
|||
|
||||
@Test
|
||||
public void testCustomizeHeaderSize() {
|
||||
bind("server.max-http-header-size", "9999");
|
||||
bind("server.max-http-header-size", "1MB");
|
||||
assertThat(this.properties.getMaxHttpHeaderSize())
|
||||
.isEqualTo(DataSize.ofBytes(9999));
|
||||
.isEqualTo(DataSize.ofMegaBytes(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomizeHeaderSizeUseBytesByDefault() {
|
||||
bind("server.max-http-header-size", "1024");
|
||||
assertThat(this.properties.getMaxHttpHeaderSize())
|
||||
.isEqualTo(DataSize.ofKiloBytes(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -121,6 +121,24 @@ public class TomcatWebServerFactoryCustomizerTests {
|
|||
.isEqualTo(10000));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customMaxHttpHeaderSize() {
|
||||
bind("server.max-http-header-size=1KB");
|
||||
customizeAndRunServer((server) -> assertThat(((AbstractHttp11Protocol<?>) server
|
||||
.getTomcat().getConnector().getProtocolHandler()).getMaxHttpHeaderSize())
|
||||
.isEqualTo(DataSize.ofKiloBytes(1).toBytes()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
public void customMaxHttpHeaderSizeWithDeprecatedProperty() {
|
||||
bind("server.max-http-header-size=4KB",
|
||||
"server.tomcat.max-http-header-size=1024");
|
||||
customizeAndRunServer((server) -> assertThat(((AbstractHttp11Protocol<?>) server
|
||||
.getTomcat().getConnector().getProtocolHandler()).getMaxHttpHeaderSize())
|
||||
.isEqualTo(DataSize.ofKiloBytes(1).toBytes()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customMaxSwallowSize() {
|
||||
bind("server.tomcat.max-swallow-size=10MB");
|
||||
|
|
|
@ -265,7 +265,6 @@ content into your application. Rather, pick only the properties that you need.
|
|||
172\\.2[0-9]{1}\\.\\d{1,3}\\.\\d{1,3}|\\
|
||||
172\\.3[0-1]{1}\\.\\d{1,3}\\.\\d{1,3} # Regular expression matching trusted IP addresses.
|
||||
server.tomcat.max-connections=0 # Maximum number of connections that the server accepts and processes at any given time.
|
||||
server.tomcat.max-http-header-size=0 # Maximum size, in bytes, of the HTTP message header. Deprecated, use server.max-http-header-size instead.
|
||||
server.tomcat.max-http-post-size=0 # Maximum size, in bytes, of the HTTP post content.
|
||||
server.tomcat.max-swallow-size=2MB # Maximum amount of request body to swallow.
|
||||
server.tomcat.max-threads=0 # Maximum number of worker threads.
|
||||
|
|
Loading…
Reference in New Issue