@@ -48,14 +48,11 @@ public class FormDataTest extends BaseTest {
4848 """
4949 .replaceAll ("\\ s" , "" );
5050
51- @ Test (dataProvider = "schemes" )
52- public void post_server_configuration_max_form_data (String scheme ) throws Exception {
53- // Fixed length. n, n is < max length, Ok.
54- // Fixed length. n, n > too big
55- // Not tested yet: Chunked, too big.
56-
51+ @ Test (dataProvider = "schemesAndChunked" )
52+ public void post_server_configuration_max_form_data (String scheme , boolean chunked ) throws Exception {
5753 // File too big even though the overall request size is ok.
5854 withScheme (scheme )
55+ .withChunked (chunked )
5956 .withBodyParameterCount (4096 )
6057 .withBodyParameterSize (32 )
6158 // Body is [180,223]
@@ -75,7 +72,8 @@ public void post_server_configuration_max_form_data(String scheme) throws Except
7572
7673 // Exceeded
7774 withScheme (scheme )
78- .withBodyParameterCount (42 * 1024 ) // 131,072, 131,072
75+ .withChunked (chunked )
76+ .withBodyParameterCount (42 * 1024 ) // 43,008
7977 .withBodyParameterSize (128 )
8078 // 4k * 33 > 128k
8179 .withConfiguration (config -> config .withMaxFormDataSize (128 * 1024 ))
@@ -89,6 +87,7 @@ public void post_server_configuration_max_form_data(String scheme) throws Except
8987
9088 // Large, but max size has been disabled
9189 withScheme (scheme )
90+ .withChunked (chunked )
9291 .withBodyParameterCount (42 * 1024 ) // 131,072, 131,072
9392 .withBodyParameterSize (128 )
9493 // Disable the limit
@@ -155,7 +154,6 @@ public void post_server_configuration_max_request_header_size(String scheme) thr
155154 \r
156155 {"version":"42"}""" )
157156 .expectNoExceptionOnWrite ();
158-
159157 }
160158
161159 private Builder withScheme (String scheme ) {
@@ -168,6 +166,8 @@ private class Builder {
168166
169167 private int bodyParameterSize = 42 ;
170168
169+ private boolean chunked ;
170+
171171 private Consumer <HTTPServerConfiguration > configuration ;
172172
173173 private int headerCount ;
@@ -257,11 +257,20 @@ public Builder expectResponse(String response) throws Exception {
257257 body += String .join ("&" , bodyParameters );
258258 }
259259
260- var contentLength = body .getBytes (StandardCharsets .UTF_8 ).length ;
261- if (contentLength > 0 ) {
260+ if (chunked ) {
262261 request += """
263- Content-Length: {contentLength}\r
264- """ .replace ("{contentLength}" , contentLength + "" );
262+ Transfer-Encoding: chunked\r
263+ """ ;
264+
265+ // Convert body to chunked
266+ body = chunkItUp (body , null );
267+ } else {
268+ var contentLength = body .getBytes (StandardCharsets .UTF_8 ).length ;
269+ if (contentLength > 0 ) {
270+ request += """
271+ Content-Length: {contentLength}\r
272+ """ .replace ("{contentLength}" , contentLength + "" );
273+ }
265274 }
266275
267276 List <String > headers = new ArrayList <>();
@@ -273,9 +282,7 @@ public Builder expectResponse(String response) throws Exception {
273282 request += String .join ("\r \n " , headers ) + "\r \n " ;
274283 }
275284
276- request += """
277- \r
278- {body}""" .replace ("{body}" , body );
285+ request = request + "\r \n " + body ;
279286
280287 var os = socket .getOutputStream ();
281288 // Do our best to write, but ignore exceptions.
@@ -301,6 +308,11 @@ public Builder withBodyParameterSize(int bodyParameterSize) {
301308 return this ;
302309 }
303310
311+ public Builder withChunked (boolean chunked ) {
312+ this .chunked = chunked ;
313+ return this ;
314+ }
315+
304316 public Builder withConfiguration (Consumer <HTTPServerConfiguration > configuration ) throws Exception {
305317 this .configuration = configuration ;
306318 return this ;
0 commit comments