* Checks the size of the HTTP headers * @param {object} requestHeaders - HTTP request headers * @return {object} object with error or null
(requestHeaders)
| 7 | * @return {object} object with error or null |
| 8 | */ |
| 9 | function checkHttpHeadersSize(requestHeaders) { |
| 10 | let httpHeadersSize = 0; |
| 11 | |
| 12 | Object.keys(requestHeaders).forEach(header => { |
| 13 | httpHeadersSize += Buffer.byteLength(header, 'utf8') + |
| 14 | Buffer.byteLength(requestHeaders[header], 'utf8'); |
| 15 | }); |
| 16 | |
| 17 | if (httpHeadersSize > maxHttpHeadersSize) { |
| 18 | return { |
| 19 | httpHeadersSizeError: errors.HttpHeadersTooLarge, |
| 20 | }; |
| 21 | } |
| 22 | return {}; |
| 23 | } |
| 24 | |
| 25 | module.exports = checkHttpHeadersSize; |