Skip to content

Commit 8771b34

Browse files
committed
Polish "Align max HTTP header size configuration"
Closes gh-14234
1 parent dbbb378 commit 8771b34

File tree

5 files changed

+37
-10
lines changed

5 files changed

+37
-10
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.TimeZone;
3030

3131
import org.springframework.boot.context.properties.ConfigurationProperties;
32+
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
3233
import org.springframework.boot.context.properties.NestedConfigurationProperty;
3334
import org.springframework.boot.convert.DurationUnit;
3435
import org.springframework.boot.web.server.Compression;
@@ -84,7 +85,7 @@ public class ServerProperties {
8485
/**
8586
* Maximum size of the HTTP message header.
8687
*/
87-
private DataSize maxHttpHeaderSize = DataSize.ofKiloBytes(8L);
88+
private DataSize maxHttpHeaderSize = DataSize.ofKiloBytes(8);
8889

8990
/**
9091
* Time that connectors wait for another HTTP request before closing the connection.
@@ -328,9 +329,7 @@ public static class Tomcat {
328329

329330
/**
330331
* Maximum size, in bytes, of the HTTP message header.
331-
* @deprecated since 2.1.0 in favor of {@link ServerProperties#maxHttpHeaderSize}
332332
*/
333-
@Deprecated
334333
private int maxHttpHeaderSize = 0;
335334

336335
/**
@@ -496,10 +495,17 @@ public void setMaxConnections(int maxConnections) {
496495
this.maxConnections = maxConnections;
497496
}
498497

498+
@Deprecated
499+
@DeprecatedConfigurationProperty(replacement = "server.max-http-header-size")
499500
public int getMaxHttpHeaderSize() {
500501
return this.maxHttpHeaderSize;
501502
}
502503

504+
@Deprecated
505+
public void setMaxHttpHeaderSize(int maxHttpHeaderSize) {
506+
this.maxHttpHeaderSize = maxHttpHeaderSize;
507+
}
508+
503509
public DataSize getMaxSwallowSize() {
504510
return this.maxSwallowSize;
505511
}
@@ -508,10 +514,6 @@ public void setMaxSwallowSize(DataSize maxSwallowSize) {
508514
this.maxSwallowSize = maxSwallowSize;
509515
}
510516

511-
public void setMaxHttpHeaderSize(int maxHttpHeaderSize) {
512-
this.maxHttpHeaderSize = maxHttpHeaderSize;
513-
}
514-
515517
public int getAcceptCount() {
516518
return this.acceptCount;
517519
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/TomcatWebServerFactoryCustomizer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ private boolean isPositive(int value) {
116116
return value > 0;
117117
}
118118

119+
@SuppressWarnings("deprecation")
119120
private DataSize determineMaxHttpHeaderSize() {
120121
return isPositive(this.serverProperties.getTomcat().getMaxHttpHeaderSize())
121122
? DataSize

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,16 @@ public void testCustomizeUriEncoding() {
136136

137137
@Test
138138
public void testCustomizeHeaderSize() {
139-
bind("server.max-http-header-size", "9999");
139+
bind("server.max-http-header-size", "1MB");
140140
assertThat(this.properties.getMaxHttpHeaderSize())
141-
.isEqualTo(DataSize.ofBytes(9999));
141+
.isEqualTo(DataSize.ofMegaBytes(1));
142+
}
143+
144+
@Test
145+
public void testCustomizeHeaderSizeUseBytesByDefault() {
146+
bind("server.max-http-header-size", "1024");
147+
assertThat(this.properties.getMaxHttpHeaderSize())
148+
.isEqualTo(DataSize.ofKiloBytes(1));
142149
}
143150

144151
@Test

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/TomcatWebServerFactoryCustomizerTests.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,24 @@ public void customMaxHttpPostSize() {
121121
.isEqualTo(10000));
122122
}
123123

124+
@Test
125+
public void customMaxHttpHeaderSize() {
126+
bind("server.max-http-header-size=1KB");
127+
customizeAndRunServer((server) -> assertThat(((AbstractHttp11Protocol<?>) server
128+
.getTomcat().getConnector().getProtocolHandler()).getMaxHttpHeaderSize())
129+
.isEqualTo(DataSize.ofKiloBytes(1).toBytes()));
130+
}
131+
132+
@Test
133+
@Deprecated
134+
public void customMaxHttpHeaderSizeWithDeprecatedProperty() {
135+
bind("server.max-http-header-size=4KB",
136+
"server.tomcat.max-http-header-size=1024");
137+
customizeAndRunServer((server) -> assertThat(((AbstractHttp11Protocol<?>) server
138+
.getTomcat().getConnector().getProtocolHandler()).getMaxHttpHeaderSize())
139+
.isEqualTo(DataSize.ofKiloBytes(1).toBytes()));
140+
}
141+
124142
@Test
125143
public void customMaxSwallowSize() {
126144
bind("server.tomcat.max-swallow-size=10MB");

spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,6 @@ content into your application. Rather, pick only the properties that you need.
265265
172\\.2[0-9]{1}\\.\\d{1,3}\\.\\d{1,3}|\\
266266
172\\.3[0-1]{1}\\.\\d{1,3}\\.\\d{1,3} # Regular expression matching trusted IP addresses.
267267
server.tomcat.max-connections=0 # Maximum number of connections that the server accepts and processes at any given time.
268-
server.tomcat.max-http-header-size=0 # Maximum size, in bytes, of the HTTP message header. Deprecated, use server.max-http-header-size instead.
269268
server.tomcat.max-http-post-size=0 # Maximum size, in bytes, of the HTTP post content.
270269
server.tomcat.max-swallow-size=2MB # Maximum amount of request body to swallow.
271270
server.tomcat.max-threads=0 # Maximum number of worker threads.

0 commit comments

Comments
 (0)