diff options
author | simov <simeonvelichkov@gmail.com> | 2021-03-08 22:27:49 +0300 |
---|---|---|
committer | Michaƫl Zasso <targos@protonmail.com> | 2021-05-01 13:25:25 +0300 |
commit | d0115f14f66b06d6fef05d114fdf093991456a50 (patch) | |
tree | 40be51cc9f7210f07d8bc81989aed28772c6e830 /lib | |
parent | e6a79802d33bf0bf511024a79118cd7cf8ddf54d (diff) |
http: add http.ClientRequest.getRawHeaderNames()
Fixes: https://github.com/nodejs/node/issues/37641
PR-URL: https://github.com/nodejs/node/pull/37660
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/_http_outgoing.js | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index 5173dc8e9e4..7736c31c4d4 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -22,10 +22,12 @@ 'use strict'; const { + Array, ArrayIsArray, ObjectCreate, ObjectDefineProperty, ObjectKeys, + ObjectValues, ObjectPrototypeHasOwnProperty, ObjectSetPrototypeOf, MathFloor, @@ -588,6 +590,23 @@ 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]; + if (headersMap === null) return []; + + 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; +}; + + // Returns a shallow copy of the current outgoing headers. OutgoingMessage.prototype.getHeaders = function getHeaders() { const headers = this[kOutHeaders]; |