| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e6a7980 commit d0115f1
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1340,6 +1340,7 @@ The `http` module `OutgoingMessage.prototype._headers` and | |||
| 1340 | 1340 | the public methods (e.g. `OutgoingMessage.prototype.getHeader()`, | |
| 1341 | 1341 | `OutgoingMessage.prototype.getHeaders()`, | |
| 1342 | 1342 | `OutgoingMessage.prototype.getHeaderNames()`, | |
| 1343 | + `OutgoingMessage.prototype.getRawHeaderNames()`, | ||
| 1343 | 1344 | `OutgoingMessage.prototype.hasHeader()`, | |
| 1344 | 1345 | `OutgoingMessage.prototype.removeHeader()`, | |
| 1345 | 1346 | `OutgoingMessage.prototype.setHeader()`) for working with outgoing headers. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -756,6 +756,24 @@ const cookie = request.getHeader('Cookie'); | |||
| 756 | 756 | // 'cookie' is of type string[] | |
| 757 | 757 | ``` | |
| 758 | 758 | ||
| 759 | + ### `request.getRawHeaderNames()` | ||
| 760 | + <!-- YAML | ||
| 761 | + added: REPLACEME | ||
| 762 | + --> | ||
| 763 | + | ||
| 764 | + * Returns: {string[]} | ||
| 765 | + | ||
| 766 | + Returns an array containing the unique names of the current outgoing raw | ||
| 767 | + headers. Header names are returned with their exact casing being set. | ||
| 768 | + | ||
| 769 | + ```js | ||
| 770 | + request.setHeader('Foo', 'bar'); | ||
| 771 | + request.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']); | ||
| 772 | + | ||
| 773 | + const headerNames = request.getRawHeaderNames(); | ||
| 774 | + // headerNames === ['Foo', 'Set-Cookie'] | ||
| 775 | + ``` | ||
| 776 | + | ||
| 759 | 777 | ### `request.maxHeadersCount` | |
| 760 | 778 | ||
| 761 | 779 | * {number} **Default:** `2000` | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,10 +22,12 @@ | |||
| 22 | 22 | 'use strict'; | |
| 23 | 23 | ||
| 24 | 24 | const { | |
| 25 | + Array, | ||
| 25 | 26 | ArrayIsArray, | |
| 26 | 27 | ObjectCreate, | |
| 27 | 28 | ObjectDefineProperty, | |
| 28 | 29 | ObjectKeys, | |
| 30 | + ObjectValues, | ||
| 29 | 31 | ObjectPrototypeHasOwnProperty, | |
| 30 | 32 | ObjectSetPrototypeOf, | |
| 31 | 33 | MathFloor, | |
@@ -588,6 +590,23 @@ OutgoingMessage.prototype.getHeaderNames = function getHeaderNames() { | |||
| 588 | 590 | }; | |
| 589 | 591 | ||
| 590 | 592 | ||
| 593 | + // Returns an array of the names of the current outgoing raw headers. | ||
| 594 | + OutgoingMessage.prototype.getRawHeaderNames = function getRawHeaderNames() { | ||
| 595 | + const headersMap = this[kOutHeaders]; | ||
| 596 | + if (headersMap === null) return []; | ||
| 597 | + | ||
| 598 | + const values = ObjectValues(headersMap); | ||
| 599 | + const headers = Array(values.length); | ||
| 600 | + // Retain for(;;) loop for performance reasons | ||
| 601 | + // Refs: https://github.com/nodejs/node/pull/30958 | ||
| 602 | + for (let i = 0, l = values.length; i < l; i++) { | ||
| 603 | + headers[i] = values[i][0]; | ||
| 604 | + } | ||
| 605 | + | ||
| 606 | + return headers; | ||
| 607 | + }; | ||
| 608 | + | ||
| 609 | + | ||
| 591 | 610 | // Returns a shallow copy of the current outgoing headers. | |
| 592 | 611 | OutgoingMessage.prototype.getHeaders = function getHeaders() { | |
| 593 | 612 | const headers = this[kOutHeaders]; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -108,6 +108,10 @@ const s = http.createServer(common.mustCall((req, res) => { | |||
| 108 | 108 | ['x-test-header', 'x-test-header2', | |
| 109 | 109 | 'set-cookie', 'x-test-array-header']); | |
| 110 | 110 | ||
| 111 | + assert.deepStrictEqual(res.getRawHeaderNames(), | ||
| 112 | + ['x-test-header', 'X-TEST-HEADER2', | ||
| 113 | + 'set-cookie', 'x-test-array-header']); | ||
| 114 | + | ||
| 111 | 115 | assert.strictEqual(res.hasHeader('x-test-header2'), true); | |
| 112 | 116 | assert.strictEqual(res.hasHeader('X-TEST-HEADER2'), true); | |
| 113 | 117 | assert.strictEqual(res.hasHeader('X-Test-Header2'), true); | |
@@ -171,7 +175,10 @@ function nextTest() { | |||
| 171 | 175 | ||
| 172 | 176 | let bufferedResponse = ''; | |
| 173 | 177 | ||
| 174 | - http.get({ port: s.address().port }, common.mustCall((response) => { | ||
| 178 | + const req = http.get({ | ||
| 179 | + port: s.address().port, | ||
| 180 | + headers: { 'X-foo': 'bar' } | ||
| 181 | + }, common.mustCall((response) => { | ||
| 175 | 182 | switch (test) { | |
| 176 | 183 | case 'headers': | |
| 177 | 184 | assert.strictEqual(response.statusCode, 201); | |
@@ -214,4 +221,10 @@ function nextTest() { | |||
| 214 | 221 | common.mustCall(nextTest)(); | |
| 215 | 222 | })); | |
| 216 | 223 | })); | |
| 224 | + | ||
| 225 | + assert.deepStrictEqual(req.getHeaderNames(), | ||
| 226 | + ['x-foo', 'host']); | ||
| 227 | + | ||
| 228 | + assert.deepStrictEqual(req.getRawHeaderNames(), | ||
| 229 | + ['X-foo', 'Host']); | ||
| 217 | 230 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments