File tree Expand file tree Collapse file tree 2 files changed +32
-2
lines changed
Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -59,9 +59,13 @@ const MAX_HEADER_PAIRS = 2000;
5959// called to process trailing HTTP headers.
6060function parserOnHeaders ( headers , url ) {
6161 // Once we exceeded headers limit - stop collecting them
62- if ( this . maxHeaderPairs <= 0 ||
63- this . _headers . length < this . maxHeaderPairs ) {
62+ if ( this . maxHeaderPairs <= 0 ) {
6463 this . _headers . push ( ...headers ) ;
64+ } else {
65+ const remaining = this . maxHeaderPairs - this . _headers . length ;
66+ if ( remaining > 0 ) {
67+ this . _headers . push ( ...headers . slice ( 0 , remaining ) ) ;
68+ }
6569 }
6670 this . _url += url ;
6771}
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+ const common = require ( '../common' ) ;
3+ const assert = require ( 'assert' ) ;
4+ const http = require ( 'http' ) ;
5+ const net = require ( 'net' ) ;
6+
7+ const server = http . createServer ( common . mustCall ( ( req , res ) => {
8+ const limit = server . maxHeadersCount * 2 ;
9+ assert . ok ( req . rawHeaders . length <= limit ,
10+ `rawHeaders.length (${ req . rawHeaders . length } ) exceeds limit (${ limit } )` ) ;
11+ res . end ( ) ;
12+ server . close ( ) ;
13+ } ) ) ;
14+
15+ server . maxHeadersCount = 50 ;
16+
17+ server . listen ( 0 , common . mustCall ( ( ) => {
18+ const port = server . address ( ) . port ;
19+ const headers = Array . from ( { length : 65 } , ( _ , i ) => `X-${ i } :v` ) . join ( '\r\n' ) ;
20+ const req = `GET / HTTP/1.1\r\nHost: localhost\r\n${ headers } \r\n\r\n` ;
21+
22+ net . createConnection ( port , 'localhost' , function ( ) {
23+ this . write ( req ) ;
24+ this . once ( 'data' , ( ) => this . end ( ) ) ;
25+ } ) ;
26+ } ) ) ;
You can’t perform that action at this time.
0 commit comments