Skip to content

Commit 98adecf

Browse files
committed
http: add http.ClientRequest.getRawHeaderNames()
Fixes: nodejs#37641
1 parent 20009d7 commit 98adecf

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/_http_outgoing.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const {
3535
ObjectCreate,
3636
ObjectDefineProperty,
3737
ObjectKeys,
38+
ObjectValues,
3839
ObjectPrototypeHasOwnProperty,
3940
ObjectSetPrototypeOf,
4041
RegExpPrototypeTest,
@@ -602,6 +603,12 @@ OutgoingMessage.prototype.getHeaderNames = function getHeaderNames() {
602603
};
603604

604605

606+
// Returns an array of the names of the current outgoing raw headers.
607+
OutgoingMessage.prototype.getRawHeaderNames = function getRawHeaderNames() {
608+
return this[kOutHeaders] !== null ? ObjectValues(this[kOutHeaders]) : [];
609+
};
610+
611+
605612
// Returns a shallow copy of the current outgoing headers.
606613
OutgoingMessage.prototype.getHeaders = function getHeaders() {
607614
const headers = this[kOutHeaders];

test/parallel/test-http-mutable-headers.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ function nextTest() {
171171

172172
let bufferedResponse = '';
173173

174-
http.get({ port: s.address().port }, common.mustCall((response) => {
174+
const req = http.get({ port: s.address().port, headers: {'X-foo': 'bar'} }, common.mustCall((response) => {
175175
switch (test) {
176176
case 'headers':
177177
assert.strictEqual(response.statusCode, 201);
@@ -214,4 +214,9 @@ function nextTest() {
214214
common.mustCall(nextTest)();
215215
}));
216216
}));
217+
218+
assert.deepStrictEqual(req.getHeaderNames(),
219+
['x-foo', 'host']);
220+
assert.deepStrictEqual(req.getRawHeaderNames(),
221+
['X-foo', 'Host']);
217222
}

0 commit comments

Comments
 (0)