Skip to content

Commit

Permalink
Configure max HTTP header size when using HTTP2 with Tomcat
Browse files Browse the repository at this point in the history
Closes gh-31322
  • Loading branch information
wilkinsona committed Jun 10, 2022
1 parent ed897fc commit e02803d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,11 @@ private void customizeMaxHttpHeaderSize(ConfigurableTomcatWebServerFactory facto
if (handler instanceof AbstractHttp11Protocol) {
AbstractHttp11Protocol protocol = (AbstractHttp11Protocol) handler;
protocol.setMaxHttpHeaderSize(maxHttpHeaderSize);
for (UpgradeProtocol upgradeProtocol : protocol.findUpgradeProtocols()) {
if (upgradeProtocol instanceof Http2Protocol) {
((Http2Protocol) upgradeProtocol).setMaxHeaderSize(maxHttpHeaderSize);
}
}
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,19 @@ void customMaxHttpHeaderSize() {
.getMaxHttpHeaderSize()).isEqualTo(DataSize.ofKilobytes(1).toBytes()));
}

@Test
void customMaxHttpHeaderSizeWithHttp2() {
bind("server.max-http-header-size=1KB", "server.http2.enabled=true");
customizeAndRunServer((server) -> {
AbstractHttp11Protocol<?> protocolHandler = (AbstractHttp11Protocol<?>) server.getTomcat().getConnector()
.getProtocolHandler();
long expectedSize = DataSize.ofKilobytes(1).toBytes();
assertThat(protocolHandler.getMaxHttpHeaderSize()).isEqualTo(expectedSize);
assertThat(((Http2Protocol) protocolHandler.getUpgradeProtocol("h2c")).getMaxHeaderSize())
.isEqualTo(expectedSize);
});
}

@Test
void customMaxHttpHeaderSizeIgnoredIfNegative() {
bind("server.max-http-header-size=-1");
Expand Down

0 comments on commit e02803d

Please sign in to comment.