mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Polish "Set max request header size on Netty when using HTTP/2"
See gh-36766
This commit is contained in:
parent
ee5b23bb02
commit
dc62e5fbc3
@ -66,8 +66,11 @@ public class NettyWebServerFactoryCustomizer
|
||||
.to((idleTimeout) -> customizeIdleTimeout(factory, idleTimeout));
|
||||
propertyMapper.from(nettyProperties::getMaxKeepAliveRequests)
|
||||
.to((maxKeepAliveRequests) -> customizeMaxKeepAliveRequests(factory, maxKeepAliveRequests));
|
||||
propertyMapper.from(this.serverProperties.getMaxHttpRequestHeaderSize())
|
||||
.to((maxHttpRequestHeaderSize) -> customizeHttp2MaxHeaderSize(factory, maxHttpRequestHeaderSize.toBytes()));
|
||||
if (this.serverProperties.getHttp2() != null && this.serverProperties.getHttp2().isEnabled()) {
|
||||
propertyMapper.from(this.serverProperties.getMaxHttpHeaderSize())
|
||||
.whenNonNull()
|
||||
.to((size) -> customizeHttp2MaxHeaderSize(factory, size.toBytes()));
|
||||
}
|
||||
customizeRequestDecoder(factory, propertyMapper);
|
||||
}
|
||||
|
||||
@ -120,9 +123,9 @@ public class NettyWebServerFactoryCustomizer
|
||||
factory.addServerCustomizers((httpServer) -> httpServer.maxKeepAliveRequests(maxKeepAliveRequests));
|
||||
}
|
||||
|
||||
private void customizeHttp2MaxHeaderSize(NettyReactiveWebServerFactory factory, long maxHttpRequestHeaderSize) {
|
||||
factory.addServerCustomizers(((httpServer) -> httpServer.http2Settings(
|
||||
(http2SettingsSpecBuilder) -> http2SettingsSpecBuilder.maxHeaderListSize(maxHttpRequestHeaderSize))));
|
||||
private void customizeHttp2MaxHeaderSize(NettyReactiveWebServerFactory factory, long size) {
|
||||
factory.addServerCustomizers(
|
||||
((httpServer) -> httpServer.http2Settings((settings) -> settings.maxHeaderListSize(size))));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -130,6 +130,7 @@ class NettyWebServerFactoryCustomizerTests {
|
||||
@Test
|
||||
void setHttp2MaxRequestHeaderSize() {
|
||||
DataSize headerSize = DataSize.ofKilobytes(24);
|
||||
this.serverProperties.getHttp2().setEnabled(true);
|
||||
this.serverProperties.setMaxHttpHeaderSize(headerSize);
|
||||
NettyReactiveWebServerFactory factory = mock(NettyReactiveWebServerFactory.class);
|
||||
this.customizer.customize(factory);
|
||||
@ -147,8 +148,8 @@ class NettyWebServerFactoryCustomizerTests {
|
||||
nettyProperties.setMaxInitialLineLength(DataSize.ofKilobytes(32));
|
||||
NettyReactiveWebServerFactory factory = mock(NettyReactiveWebServerFactory.class);
|
||||
this.customizer.customize(factory);
|
||||
then(factory).should(times(2)).addServerCustomizers(this.customizerCaptor.capture());
|
||||
NettyServerCustomizer serverCustomizer = this.customizerCaptor.getAllValues().get(1);
|
||||
then(factory).should().addServerCustomizers(this.customizerCaptor.capture());
|
||||
NettyServerCustomizer serverCustomizer = this.customizerCaptor.getAllValues().get(0);
|
||||
HttpServer httpServer = serverCustomizer.apply(HttpServer.create());
|
||||
HttpRequestDecoderSpec decoder = httpServer.configuration().decoder();
|
||||
assertThat(decoder.validateHeaders()).isFalse();
|
||||
@ -164,7 +165,7 @@ class NettyWebServerFactoryCustomizerTests {
|
||||
then(factory).should(never()).addServerCustomizers(any(NettyServerCustomizer.class));
|
||||
return;
|
||||
}
|
||||
then(factory).should(times(3)).addServerCustomizers(this.customizerCaptor.capture());
|
||||
then(factory).should(times(2)).addServerCustomizers(this.customizerCaptor.capture());
|
||||
NettyServerCustomizer serverCustomizer = this.customizerCaptor.getAllValues().get(0);
|
||||
HttpServer httpServer = serverCustomizer.apply(HttpServer.create());
|
||||
Map<ChannelOption<?>, ?> options = httpServer.configuration().options();
|
||||
@ -176,7 +177,7 @@ class NettyWebServerFactoryCustomizerTests {
|
||||
then(factory).should(never()).addServerCustomizers(any(NettyServerCustomizer.class));
|
||||
return;
|
||||
}
|
||||
then(factory).should(times(3)).addServerCustomizers(this.customizerCaptor.capture());
|
||||
then(factory).should(times(2)).addServerCustomizers(this.customizerCaptor.capture());
|
||||
NettyServerCustomizer serverCustomizer = this.customizerCaptor.getAllValues().get(0);
|
||||
HttpServer httpServer = serverCustomizer.apply(HttpServer.create());
|
||||
Duration idleTimeout = httpServer.configuration().idleTimeout();
|
||||
@ -184,7 +185,7 @@ class NettyWebServerFactoryCustomizerTests {
|
||||
}
|
||||
|
||||
private void verifyMaxKeepAliveRequests(NettyReactiveWebServerFactory factory, int expected) {
|
||||
then(factory).should(times(3)).addServerCustomizers(this.customizerCaptor.capture());
|
||||
then(factory).should(times(2)).addServerCustomizers(this.customizerCaptor.capture());
|
||||
NettyServerCustomizer serverCustomizer = this.customizerCaptor.getAllValues().get(0);
|
||||
HttpServer httpServer = serverCustomizer.apply(HttpServer.create());
|
||||
int maxKeepAliveRequests = httpServer.configuration().maxKeepAliveRequests();
|
||||
|
Loading…
Reference in New Issue
Block a user