2626import org .mockito .ArgumentCaptor ;
2727import org .mockito .Captor ;
2828import org .mockito .junit .jupiter .MockitoExtension ;
29+ import reactor .netty .http .Http2SettingsSpec ;
2930import reactor .netty .http .server .HttpRequestDecoderSpec ;
3031import reactor .netty .http .server .HttpServer ;
3132
@@ -126,21 +127,32 @@ void setMaxKeepAliveRequests() {
126127 verifyMaxKeepAliveRequests (factory , 100 );
127128 }
128129
130+ @ Test
131+ void setHttp2MaxRequestHeaderSize () {
132+ DataSize headerSize = DataSize .ofKilobytes (24 );
133+ this .serverProperties .setMaxHttpHeaderSize (headerSize );
134+ NettyReactiveWebServerFactory factory = mock (NettyReactiveWebServerFactory .class );
135+ this .customizer .customize (factory );
136+ verifyHttp2MaxHeaderSize (factory , headerSize .toBytes ());
137+ }
138+
129139 @ Test
130140 void configureHttpRequestDecoder () {
131141 ServerProperties .Netty nettyProperties = this .serverProperties .getNetty ();
142+ this .serverProperties .setMaxHttpHeaderSize (DataSize .ofKilobytes (24 ));
132143 nettyProperties .setValidateHeaders (false );
133144 nettyProperties .setInitialBufferSize (DataSize .ofBytes (512 ));
134145 nettyProperties .setH2cMaxContentLength (DataSize .ofKilobytes (1 ));
135146 nettyProperties .setMaxChunkSize (DataSize .ofKilobytes (16 ));
136147 nettyProperties .setMaxInitialLineLength (DataSize .ofKilobytes (32 ));
137148 NettyReactiveWebServerFactory factory = mock (NettyReactiveWebServerFactory .class );
138149 this .customizer .customize (factory );
139- then (factory ).should ().addServerCustomizers (this .customizerCaptor .capture ());
140- NettyServerCustomizer serverCustomizer = this .customizerCaptor .getValue ( );
150+ then (factory ).should (times ( 2 ) ).addServerCustomizers (this .customizerCaptor .capture ());
151+ NettyServerCustomizer serverCustomizer = this .customizerCaptor .getAllValues (). get ( 1 );
141152 HttpServer httpServer = serverCustomizer .apply (HttpServer .create ());
142153 HttpRequestDecoderSpec decoder = httpServer .configuration ().decoder ();
143154 assertThat (decoder .validateHeaders ()).isFalse ();
155+ assertThat (decoder .maxHeaderSize ()).isEqualTo (this .serverProperties .getMaxHttpHeaderSize ().toBytes ());
144156 assertThat (decoder .initialBufferSize ()).isEqualTo (nettyProperties .getInitialBufferSize ().toBytes ());
145157 assertThat (decoder .h2cMaxContentLength ()).isEqualTo (nettyProperties .getH2cMaxContentLength ().toBytes ());
146158 assertThat (decoder .maxChunkSize ()).isEqualTo (nettyProperties .getMaxChunkSize ().toBytes ());
@@ -152,7 +164,7 @@ private void verifyConnectionTimeout(NettyReactiveWebServerFactory factory, Inte
152164 then (factory ).should (never ()).addServerCustomizers (any (NettyServerCustomizer .class ));
153165 return ;
154166 }
155- then (factory ).should (times (2 )).addServerCustomizers (this .customizerCaptor .capture ());
167+ then (factory ).should (times (3 )).addServerCustomizers (this .customizerCaptor .capture ());
156168 NettyServerCustomizer serverCustomizer = this .customizerCaptor .getAllValues ().get (0 );
157169 HttpServer httpServer = serverCustomizer .apply (HttpServer .create ());
158170 Map <ChannelOption <?>, ?> options = httpServer .configuration ().options ();
@@ -164,19 +176,27 @@ private void verifyIdleTimeout(NettyReactiveWebServerFactory factory, Duration e
164176 then (factory ).should (never ()).addServerCustomizers (any (NettyServerCustomizer .class ));
165177 return ;
166178 }
167- then (factory ).should (times (2 )).addServerCustomizers (this .customizerCaptor .capture ());
179+ then (factory ).should (times (3 )).addServerCustomizers (this .customizerCaptor .capture ());
168180 NettyServerCustomizer serverCustomizer = this .customizerCaptor .getAllValues ().get (0 );
169181 HttpServer httpServer = serverCustomizer .apply (HttpServer .create ());
170182 Duration idleTimeout = httpServer .configuration ().idleTimeout ();
171183 assertThat (idleTimeout ).isEqualTo (expected );
172184 }
173185
174186 private void verifyMaxKeepAliveRequests (NettyReactiveWebServerFactory factory , int expected ) {
175- then (factory ).should (times (2 )).addServerCustomizers (this .customizerCaptor .capture ());
187+ then (factory ).should (times (3 )).addServerCustomizers (this .customizerCaptor .capture ());
176188 NettyServerCustomizer serverCustomizer = this .customizerCaptor .getAllValues ().get (0 );
177189 HttpServer httpServer = serverCustomizer .apply (HttpServer .create ());
178190 int maxKeepAliveRequests = httpServer .configuration ().maxKeepAliveRequests ();
179191 assertThat (maxKeepAliveRequests ).isEqualTo (expected );
180192 }
181193
194+ private void verifyHttp2MaxHeaderSize (NettyReactiveWebServerFactory factory , long expected ) {
195+ then (factory ).should (times (2 )).addServerCustomizers (this .customizerCaptor .capture ());
196+ NettyServerCustomizer serverCustomizer = this .customizerCaptor .getAllValues ().get (0 );
197+ HttpServer httpServer = serverCustomizer .apply (HttpServer .create ());
198+ Http2SettingsSpec decoder = httpServer .configuration ().http2SettingsSpec ();
199+ assertThat (decoder .maxHeaderListSize ()).isEqualTo (expected );
200+ }
201+
182202}
0 commit comments