diff --git a/HISTORY.md b/HISTORY.md index 520f4d8..97c9df8 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,6 +1,7 @@ unreleased ================== + * refactor: replace setHeaders function with optimized inline header setting * remove unnecessary devDependency `safe-buffer` * remove `unpipe` package and use native `unpipe()` method * remove unnecessary devDependency `readable-stream` diff --git a/index.js b/index.js index f887765..f015e88 100644 --- a/index.js +++ b/index.js @@ -288,7 +288,9 @@ function send (req, res, status, headers, message) { res.removeHeader('Content-Range') // response headers - setHeaders(res, headers) + for (const [key, value] of Object.entries(headers ?? {})) { + res.setHeader(key, value) + } // security headers res.setHeader('Content-Security-Policy', "default-src 'none'") @@ -318,23 +320,3 @@ function send (req, res, status, headers, message) { onFinished(req, write) req.resume() } - -/** - * Set response headers from an object. - * - * @param {OutgoingMessage} res - * @param {object} headers - * @private - */ - -function setHeaders (res, headers) { - if (!headers) { - return - } - - var keys = Object.keys(headers) - for (var i = 0; i < keys.length; i++) { - var key = keys[i] - res.setHeader(key, headers[key]) - } -}