diff --git a/index.js b/index.js index 5bb7894..2041572 100644 --- a/index.js +++ b/index.js @@ -16,6 +16,7 @@ const { PROMETHEUS_WITH_METHOD = 'true', PROMETHEUS_WITH_STATUS = 'true', PROMETHEUS_METRIC_TYPE = 'summary', + MAX_HEADER_SIZE = 1048576 } = process.env const sleep = promisify(setTimeout); @@ -189,22 +190,27 @@ app.all('*', (req, res) => { }); -let sslOpts = { +let httpOpts = { + maxHeaderSize: MAX_HEADER_SIZE +} + +let httpsOpts = { key: require('fs').readFileSync(process.env.HTTPS_KEY_FILE || 'privkey.pem'), - cert: require('fs').readFileSync(process.env.HTTPS_CERT_FILE || 'fullchain.pem') + cert: require('fs').readFileSync(process.env.HTTPS_CERT_FILE || 'fullchain.pem'), + maxHeaderSize: MAX_HEADER_SIZE }; //Whether to enable the client certificate feature if(process.env.MTLS_ENABLE){ - sslOpts = { + httpsOpts = { requestCert: true, rejectUnauthorized: false, - ...sslOpts + ...httpsOpts } } -var httpServer = http.createServer(app).listen(process.env.HTTP_PORT || 8080); -var httpsServer = https.createServer(sslOpts,app).listen(process.env.HTTPS_PORT || 8443); +var httpServer = http.createServer(httpOpts, app).listen(process.env.HTTP_PORT || 8080); +var httpsServer = https.createServer(httpsOpts,app).listen(process.env.HTTPS_PORT || 8443); console.log(`Listening on ports ${process.env.HTTP_PORT || 8080} for http, and ${process.env.HTTPS_PORT || 8443} for https.`); let calledClose = false; diff --git a/tests.sh b/tests.sh index ce94ef0..056f1c4 100755 --- a/tests.sh +++ b/tests.sh @@ -176,6 +176,17 @@ else exit 1 fi +message " Make request with a large header." +LARGE_HEADER_VALUE=$(head -c 10000