diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index f40c94eb21b23a..b7f0a9d5e67a15 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -607,15 +607,14 @@ OutgoingMessage.prototype.getHeaderNames = function getHeaderNames() { // Returns an array of the names of the current outgoing raw headers. OutgoingMessage.prototype.getRawHeaderNames = function getRawHeaderNames() { const headersMap = this[kOutHeaders]; - const headers = Array(ObjectKeys(headersMap).length); + if (headersMap === null) return []; - if (headersMap !== null) { - const values = ObjectValues(headersMap); - // Retain for(;;) loop for performance reasons - // Refs: https://github.com/nodejs/node/pull/30958 - for (let i = 0, l = values.length; i < l; i++) { - headers[i] = values[i][0]; - } + const values = ObjectValues(headersMap); + const headers = Array(values.length); + // Retain for(;;) loop for performance reasons + // Refs: https://github.com/nodejs/node/pull/30958 + for (let i = 0, l = values.length; i < l; i++) { + headers[i] = values[i][0]; } return headers;