26
26
import org .mockito .ArgumentCaptor ;
27
27
import org .mockito .Captor ;
28
28
import org .mockito .junit .jupiter .MockitoExtension ;
29
+ import reactor .netty .http .Http2SettingsSpec ;
29
30
import reactor .netty .http .server .HttpRequestDecoderSpec ;
30
31
import reactor .netty .http .server .HttpServer ;
31
32
@@ -126,21 +127,32 @@ void setMaxKeepAliveRequests() {
126
127
verifyMaxKeepAliveRequests (factory , 100 );
127
128
}
128
129
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
+
129
139
@ Test
130
140
void configureHttpRequestDecoder () {
131
141
ServerProperties .Netty nettyProperties = this .serverProperties .getNetty ();
142
+ this .serverProperties .setMaxHttpHeaderSize (DataSize .ofKilobytes (24 ));
132
143
nettyProperties .setValidateHeaders (false );
133
144
nettyProperties .setInitialBufferSize (DataSize .ofBytes (512 ));
134
145
nettyProperties .setH2cMaxContentLength (DataSize .ofKilobytes (1 ));
135
146
nettyProperties .setMaxChunkSize (DataSize .ofKilobytes (16 ));
136
147
nettyProperties .setMaxInitialLineLength (DataSize .ofKilobytes (32 ));
137
148
NettyReactiveWebServerFactory factory = mock (NettyReactiveWebServerFactory .class );
138
149
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 );
141
152
HttpServer httpServer = serverCustomizer .apply (HttpServer .create ());
142
153
HttpRequestDecoderSpec decoder = httpServer .configuration ().decoder ();
143
154
assertThat (decoder .validateHeaders ()).isFalse ();
155
+ assertThat (decoder .maxHeaderSize ()).isEqualTo (this .serverProperties .getMaxHttpHeaderSize ().toBytes ());
144
156
assertThat (decoder .initialBufferSize ()).isEqualTo (nettyProperties .getInitialBufferSize ().toBytes ());
145
157
assertThat (decoder .h2cMaxContentLength ()).isEqualTo (nettyProperties .getH2cMaxContentLength ().toBytes ());
146
158
assertThat (decoder .maxChunkSize ()).isEqualTo (nettyProperties .getMaxChunkSize ().toBytes ());
@@ -152,7 +164,7 @@ private void verifyConnectionTimeout(NettyReactiveWebServerFactory factory, Inte
152
164
then (factory ).should (never ()).addServerCustomizers (any (NettyServerCustomizer .class ));
153
165
return ;
154
166
}
155
- then (factory ).should (times (2 )).addServerCustomizers (this .customizerCaptor .capture ());
167
+ then (factory ).should (times (3 )).addServerCustomizers (this .customizerCaptor .capture ());
156
168
NettyServerCustomizer serverCustomizer = this .customizerCaptor .getAllValues ().get (0 );
157
169
HttpServer httpServer = serverCustomizer .apply (HttpServer .create ());
158
170
Map <ChannelOption <?>, ?> options = httpServer .configuration ().options ();
@@ -164,19 +176,27 @@ private void verifyIdleTimeout(NettyReactiveWebServerFactory factory, Duration e
164
176
then (factory ).should (never ()).addServerCustomizers (any (NettyServerCustomizer .class ));
165
177
return ;
166
178
}
167
- then (factory ).should (times (2 )).addServerCustomizers (this .customizerCaptor .capture ());
179
+ then (factory ).should (times (3 )).addServerCustomizers (this .customizerCaptor .capture ());
168
180
NettyServerCustomizer serverCustomizer = this .customizerCaptor .getAllValues ().get (0 );
169
181
HttpServer httpServer = serverCustomizer .apply (HttpServer .create ());
170
182
Duration idleTimeout = httpServer .configuration ().idleTimeout ();
171
183
assertThat (idleTimeout ).isEqualTo (expected );
172
184
}
173
185
174
186
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 ());
176
188
NettyServerCustomizer serverCustomizer = this .customizerCaptor .getAllValues ().get (0 );
177
189
HttpServer httpServer = serverCustomizer .apply (HttpServer .create ());
178
190
int maxKeepAliveRequests = httpServer .configuration ().maxKeepAliveRequests ();
179
191
assertThat (maxKeepAliveRequests ).isEqualTo (expected );
180
192
}
181
193
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
+
182
202
}
0 commit comments