From 487b6f5de401619ccc877d93010ee5c44410957d Mon Sep 17 00:00:00 2001 From: Gil Pedersen Date: Fri, 22 Mar 2024 14:37:01 +0100 Subject: [PATCH] Only iterate headers once --- lib/index.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/index.js b/lib/index.js index cbaf81f..b14c4c9 100755 --- a/lib/index.js +++ b/lib/index.js @@ -115,12 +115,15 @@ internals.Client = class { } uri.method = method.toUpperCase(); - uri.headers = Object.assign({}, options.headers); + uri.headers = Object.create(null); const usedHeaders = new Set(); - for (const [key, value] of Object.entries(uri.headers)) { - if (value !== undefined) { - usedHeaders.add(key.toLowerCase()); + if (options.headers) { + for (const [key, value] of Object.entries(options.headers)) { + if (value !== undefined) { + uri.headers[key] = value; + usedHeaders.add(key.toLowerCase()); + } } }