-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cli: add --max-http-header-size flag
Allow the maximum size of HTTP headers to be overridden from the command line. co-authored-by: Matteo Collina <hello@matteocollina.com> PR-URL: #24811 Fixes: #24692 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
- Loading branch information
1 parent
c80ac7f
commit edd8bd0
Showing
7 changed files
with
184 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const { spawn } = require('child_process'); | ||
const path = require('path'); | ||
const testName = path.join(__dirname, 'test-http-max-http-headers.js'); | ||
const parsers = ['legacy', 'llhttp']; | ||
|
||
const timeout = common.platformTimeout(100); | ||
|
||
const tests = []; | ||
|
||
function test(fn) { | ||
tests.push(fn); | ||
} | ||
|
||
parsers.forEach((parser) => { | ||
test(function(cb) { | ||
console.log('running subtest expecting failure'); | ||
|
||
// Validate that the test fails if the max header size is too small. | ||
const args = ['--expose-internals', | ||
`--http-parser=${parser}`, | ||
'--max-http-header-size=1024', | ||
testName]; | ||
const cp = spawn(process.execPath, args, { stdio: 'inherit' }); | ||
|
||
cp.on('close', common.mustCall((code, signal) => { | ||
assert.strictEqual(code, 1); | ||
assert.strictEqual(signal, null); | ||
cb(); | ||
})); | ||
}); | ||
|
||
test(function(cb) { | ||
console.log('running subtest expecting success'); | ||
|
||
const env = Object.assign({}, process.env, { | ||
NODE_DEBUG: 'http' | ||
}); | ||
|
||
// Validate that the test fails if the max header size is too small. | ||
// Validate that the test now passes if the same limit becomes large enough. | ||
const args = ['--expose-internals', | ||
`--http-parser=${parser}`, | ||
'--max-http-header-size=1024', | ||
testName, | ||
'1024']; | ||
const cp = spawn(process.execPath, args, { | ||
env, | ||
stdio: 'inherit' | ||
}); | ||
|
||
cp.on('close', common.mustCall((code, signal) => { | ||
assert.strictEqual(code, 0); | ||
assert.strictEqual(signal, null); | ||
cb(); | ||
})); | ||
}); | ||
|
||
// Next, repeat the same checks using NODE_OPTIONS if it is supported. | ||
if (process.config.variables.node_without_node_options) { | ||
const env = Object.assign({}, process.env, { | ||
NODE_OPTIONS: `--http-parser=${parser} --max-http-header-size=1024` | ||
}); | ||
|
||
test(function(cb) { | ||
console.log('running subtest expecting failure'); | ||
|
||
// Validate that the test fails if the max header size is too small. | ||
const args = ['--expose-internals', testName]; | ||
const cp = spawn(process.execPath, args, { env, stdio: 'inherit' }); | ||
|
||
cp.on('close', common.mustCall((code, signal) => { | ||
assert.strictEqual(code, 1); | ||
assert.strictEqual(signal, null); | ||
cb(); | ||
})); | ||
}); | ||
|
||
test(function(cb) { | ||
// Validate that the test now passes if the same limit | ||
// becomes large enough. | ||
const args = ['--expose-internals', testName, '1024']; | ||
const cp = spawn(process.execPath, args, { env, stdio: 'inherit' }); | ||
|
||
cp.on('close', common.mustCall((code, signal) => { | ||
assert.strictEqual(code, 0); | ||
assert.strictEqual(signal, null); | ||
cb(); | ||
})); | ||
}); | ||
} | ||
}); | ||
|
||
function runTest() { | ||
const fn = tests.shift(); | ||
|
||
if (!fn) { | ||
return; | ||
} | ||
|
||
fn(() => { | ||
setTimeout(runTest, timeout); | ||
}); | ||
} | ||
|
||
runTest(); |