@@ -5,6 +5,11 @@ const http = require('http');
55const net = require ( 'net' ) ;
66const assert = require ( 'assert' ) ;
77
8+ // The maximum http chunk extension size is set in `src/node_http_parser.cc`.
9+ // These tests assert that once the extension size is reached, an HTTP 413
10+ // response is returned.
11+ // Currently, the max size is set to 16KiB (16384).
12+
813// Verify that chunk extensions are limited in size when sent all together.
914{
1015 const server = http . createServer ( ( req , res ) => {
@@ -17,7 +22,8 @@ const assert = require('assert');
1722 } ) ;
1823
1924 server . listen ( 0 , ( ) => {
20- const sock = net . connect ( server . address ( ) . port ) ;
25+ const port = server . address ( ) . port ;
26+ const sock = net . connect ( port ) ;
2127 let data = '' ;
2228
2329 sock . on ( 'data' , ( chunk ) => data += chunk . toString ( 'utf-8' ) ) ;
@@ -29,15 +35,17 @@ const assert = require('assert');
2935
3036 sock . end ( '' +
3137 'GET / HTTP/1.1\r\n' +
32- ' Host: localhost:8080 \r\n' +
38+ ` Host: localhost:${ port } \r\n` +
3339 'Transfer-Encoding: chunked\r\n\r\n' +
34- '2;' + 'A' . repeat ( 20000 ) + '=bar\r\nAA\r\n' +
35- '0\r\n\r\n'
40+ '2;' + 'a' . repeat ( 17000 ) + '\r\n' + // Chunk size + chunk ext + CRLF
41+ 'AA\r\n' + // Chunk data
42+ '0\r\n' + // Last chunk
43+ '\r\n' // End of http message
3644 ) ;
3745 } ) ;
3846}
3947
40- // Verify that chunk extensions are limited in size when sent in intervals.
48+ // Verify that chunk extensions are limited in size when sent in parts
4149{
4250 const server = http . createServer ( ( req , res ) => {
4351 req . on ( 'end' , ( ) => {
@@ -49,24 +57,10 @@ const assert = require('assert');
4957 } ) ;
5058
5159 server . listen ( 0 , ( ) => {
52- const sock = net . connect ( server . address ( ) . port ) ;
53- let remaining = 20000 ;
60+ const port = server . address ( ) . port ;
61+ const sock = net . connect ( port ) ;
5462 let data = '' ;
5563
56- const interval = setInterval (
57- ( ) => {
58- if ( remaining > 0 ) {
59- sock . write ( 'A' . repeat ( 1000 ) ) ;
60- } else {
61- sock . write ( '=bar\r\nAA\r\n0\r\n\r\n' ) ;
62- clearInterval ( interval ) ;
63- }
64-
65- remaining -= 1000 ;
66- } ,
67- common . platformTimeout ( 20 ) ,
68- ) . unref ( ) ;
69-
7064 sock . on ( 'data' , ( chunk ) => data += chunk . toString ( 'utf-8' ) ) ;
7165
7266 sock . on ( 'end' , common . mustCall ( function ( ) {
@@ -76,10 +70,20 @@ const assert = require('assert');
7670
7771 sock . write ( '' +
7872 'GET / HTTP/1.1\r\n' +
79- ' Host: localhost:8080 \r\n' +
73+ ` Host: localhost:${ port } \r\n` +
8074 'Transfer-Encoding: chunked\r\n\r\n' +
81- '2;'
75+ '2;' // Chunk size + start of chunk-extension
8276 ) ;
77+
78+ sock . write ( 'A' . repeat ( 8500 ) ) ; // Write half of the chunk-extension
79+
80+ queueMicrotask ( ( ) => {
81+ sock . write ( 'A' . repeat ( 8500 ) + '\r\n' + // Remaining half of the chunk-extension
82+ 'AA\r\n' + // Chunk data
83+ '0\r\n' + // Last chunk
84+ '\r\n' // End of http message
85+ ) ;
86+ } ) ;
8387 } ) ;
8488}
8589
@@ -95,7 +99,8 @@ const assert = require('assert');
9599 } ) ;
96100
97101 server . listen ( 0 , ( ) => {
98- const sock = net . connect ( server . address ( ) . port ) ;
102+ const port = server . address ( ) . port ;
103+ const sock = net . connect ( port ) ;
99104 let data = '' ;
100105
101106 sock . on ( 'data' , ( chunk ) => data += chunk . toString ( 'utf-8' ) ) ;
@@ -120,7 +125,7 @@ const assert = require('assert');
120125
121126 sock . end ( '' +
122127 'GET / HTTP/1.1\r\n' +
123- ' Host: localhost:8080 \r\n' +
128+ ` Host: localhost:${ port } \r\n` +
124129 'Transfer-Encoding: chunked\r\n\r\n' +
125130 '2;' + 'A' . repeat ( 10000 ) + '=bar\r\nAA\r\n' +
126131 '2;' + 'A' . repeat ( 10000 ) + '=bar\r\nAA\r\n' +
0 commit comments