Browse Source

doc, test: add note to response.getHeaders

* also correct language for the same note for querystring.parse
* add assertions for said note

PR-URL: https://github.com/nodejs/node/pull/12887
Fixes: https://github.com/nodejs/node/issues/12885
Refs: https://github.com/nodejs/node/pull/12883
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
v6
Refael Ackermann 8 years ago
parent
commit
e1cabf6fbd
  1. 7
      doc/api/http.md
  2. 6
      doc/api/querystring.md
  3. 6
      test/parallel/test-http-mutable-headers.js

7
doc/api/http.md

@ -556,7 +556,7 @@ Returns `request`.
added: v0.1.17
-->
This class inherits from [`net.Server`][] and has the following additional events:
This class inherits from [`net.Server`][] and has the following additional events:
### Event: 'checkContinue'
<!-- YAML
@ -982,6 +982,11 @@ header-related http module methods. The keys of the returned object are the
header names and the values are the respective header values. All header names
are lowercase.
*Note*: The object returned by the `response.getHeaders()` method _does not_
prototypically inherit from the JavaScript `Object`. This means that typical
`Object` methods such as `obj.toString()`, `obj.hasOwnProperty()`, and others
are not defined and *will not work*.
Example:
```js

6
doc/api/querystring.md

@ -68,9 +68,9 @@ For example, the query string `'foo=bar&abc=xyz&abc=123'` is parsed into:
```
*Note*: The object returned by the `querystring.parse()` method _does not_
prototypically extend from the JavaScript `Object`. This means that the
typical `Object` methods such as `obj.toString()`, `obj.hasOwnProperty()`,
and others are not defined and *will not work*.
prototypically inherit from the JavaScript `Object`. This means that typical
`Object` methods such as `obj.toString()`, `obj.hasOwnProperty()`, and others
are not defined and *will not work*.
By default, percent-encoded characters within the query string will be assumed
to use UTF-8 encoding. If an alternative character encoding is used, then an

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

@ -43,8 +43,9 @@ const s = http.createServer(common.mustCall((req, res) => {
switch (test) {
case 'headers':
// Check that header-related functions work before setting any headers
// eslint-disable-next-line no-restricted-properties
assert.deepEqual(res.getHeaders(), {});
const headers = res.getHeaders();
const exoticObj = Object.create(null);
assert.deepStrictEqual(headers, exoticObj);
assert.deepStrictEqual(res.getHeaderNames(), []);
assert.deepStrictEqual(res.hasHeader('Connection'), false);
assert.deepStrictEqual(res.getHeader('Connection'), undefined);
@ -72,6 +73,7 @@ const s = http.createServer(common.mustCall((req, res) => {
assert.strictEqual(res.getHeader('x-test-header2'), 'testing');
const headersCopy = res.getHeaders();
assert.strictEqual(Object.getPrototypeOf(headersCopy), null);
// eslint-disable-next-line no-restricted-properties
assert.deepEqual(headersCopy, {
'x-test-header': 'testing',

Loading…
Cancel
Save