forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
https: add
maxHeaderSize
option for https server
Fixes: nodejs#38954 Refs: nodejs#30570
- Loading branch information
Showing
3 changed files
with
134 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
|
||
if (!common.hasCrypto) { | ||
common.skip('missing crypto'); | ||
} | ||
|
||
const assert = require('assert'); | ||
const https = require('https'); | ||
const fixtures = require('../common/fixtures'); | ||
|
||
|
||
const options = { | ||
key: fixtures.readKey('agent1-key.pem'), | ||
cert: fixtures.readKey('agent1-cert.pem') | ||
}; | ||
|
||
const maxHeaderSize = 8192; | ||
|
||
const body = 'hello world\n'; | ||
const serverCallback = (req, res) => { | ||
res.writeHead(200, { 'content-type': 'text/plain' }); | ||
res.end(body); | ||
}; | ||
|
||
const commonReqOptions = { | ||
hostname: '127.0.0.1', | ||
path: '/', | ||
method: 'GET', | ||
rejectUnauthorized: false, | ||
}; | ||
|
||
// Test when header size is larger than maxHeaderSize | ||
{ | ||
const server = https.createServer({ | ||
...options, | ||
maxHeaderSize | ||
}, serverCallback); | ||
|
||
server.listen(0, common.mustCall(() => { | ||
const serverPort = server.address().port; | ||
const reqOptions = { | ||
...commonReqOptions, | ||
port: serverPort, | ||
headers: { | ||
'h': 'a'.repeat(maxHeaderSize + 1) | ||
} | ||
}; | ||
|
||
https | ||
.request(reqOptions, common.mustCall((res) => { | ||
assert.strictEqual(res.statusCode, 431); | ||
|
||
res.on('data', () => {}); | ||
|
||
res.on('end', common.mustCall(() => { | ||
server.close(); | ||
})); | ||
})) | ||
.end(); | ||
})); | ||
} | ||
|
||
// Test when header size is within the range | ||
{ | ||
const server = https.createServer({ | ||
...options, | ||
maxHeaderSize | ||
}, serverCallback); | ||
|
||
server.listen(0, common.mustCall(() => { | ||
const serverPort = server.address().port; | ||
const reqOptions = { | ||
...commonReqOptions, | ||
port: serverPort, | ||
headers: { | ||
// Some other header overhead | ||
'h': 'a'.repeat(maxHeaderSize - 200) | ||
} | ||
}; | ||
|
||
https | ||
.request(reqOptions, common.mustCall((res) => { | ||
assert.strictEqual(res.statusCode, 200); | ||
|
||
res.on('data', () => {}); | ||
|
||
res.on('end', common.mustCall(() => { | ||
server.close(); | ||
})); | ||
})) | ||
.end(); | ||
})); | ||
} | ||
|
||
|
||
// Test parameter validation | ||
{ | ||
assert.throws(common.mustCall(() => { | ||
https.createServer({ | ||
...options, | ||
maxHeaderSize: -1 | ||
}, serverCallback); | ||
}), { | ||
message: 'The value of "maxHeaderSize" is out of range. ' + | ||
'It must be >= 0 && <= 9007199254740991. Received -1', | ||
code: 'ERR_OUT_OF_RANGE', | ||
name: 'RangeError' | ||
}); | ||
|
||
assert.throws(common.mustCall(() => { | ||
https.createServer({ | ||
...options, | ||
maxHeaderSize: '' | ||
}, serverCallback); | ||
}), { | ||
message: 'The "maxHeaderSize" argument must be of type number. ' + | ||
'Received type string (\'\')', | ||
code: 'ERR_INVALID_ARG_TYPE', | ||
name: 'TypeError' | ||
}); | ||
} |