Skip to content

Commit e1cabf6

Browse files
committed
doc, test: add note to response.getHeaders
* also correct language for the same note for querystring.parse * add assertions for said note PR-URL: #12887 Fixes: #12885 Refs: #12883 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
1 parent 57a08e2 commit e1cabf6

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

doc/api/http.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ Returns `request`.
556556
added: v0.1.17
557557
-->
558558

559-
This class inherits from [`net.Server`][] and has the following additional events:
559+
This class inherits from [`net.Server`][] and has the following additional events:
560560

561561
### Event: 'checkContinue'
562562
<!-- YAML
@@ -982,6 +982,11 @@ header-related http module methods. The keys of the returned object are the
982982
header names and the values are the respective header values. All header names
983983
are lowercase.
984984

985+
*Note*: The object returned by the `response.getHeaders()` method _does not_
986+
prototypically inherit from the JavaScript `Object`. This means that typical
987+
`Object` methods such as `obj.toString()`, `obj.hasOwnProperty()`, and others
988+
are not defined and *will not work*.
989+
985990
Example:
986991

987992
```js

doc/api/querystring.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ For example, the query string `'foo=bar&abc=xyz&abc=123'` is parsed into:
6868
```
6969

7070
*Note*: The object returned by the `querystring.parse()` method _does not_
71-
prototypically extend from the JavaScript `Object`. This means that the
72-
typical `Object` methods such as `obj.toString()`, `obj.hasOwnProperty()`,
73-
and others are not defined and *will not work*.
71+
prototypically inherit from the JavaScript `Object`. This means that typical
72+
`Object` methods such as `obj.toString()`, `obj.hasOwnProperty()`, and others
73+
are not defined and *will not work*.
7474

7575
By default, percent-encoded characters within the query string will be assumed
7676
to use UTF-8 encoding. If an alternative character encoding is used, then an

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ const s = http.createServer(common.mustCall((req, res) => {
4343
switch (test) {
4444
case 'headers':
4545
// Check that header-related functions work before setting any headers
46-
// eslint-disable-next-line no-restricted-properties
47-
assert.deepEqual(res.getHeaders(), {});
46+
const headers = res.getHeaders();
47+
const exoticObj = Object.create(null);
48+
assert.deepStrictEqual(headers, exoticObj);
4849
assert.deepStrictEqual(res.getHeaderNames(), []);
4950
assert.deepStrictEqual(res.hasHeader('Connection'), false);
5051
assert.deepStrictEqual(res.getHeader('Connection'), undefined);
@@ -72,6 +73,7 @@ const s = http.createServer(common.mustCall((req, res) => {
7273
assert.strictEqual(res.getHeader('x-test-header2'), 'testing');
7374

7475
const headersCopy = res.getHeaders();
76+
assert.strictEqual(Object.getPrototypeOf(headersCopy), null);
7577
// eslint-disable-next-line no-restricted-properties
7678
assert.deepEqual(headersCopy, {
7779
'x-test-header': 'testing',

0 commit comments

Comments
 (0)