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>
This commit is contained in:
parent
57a08e2f70
commit
e1cabf6fbd
@ -556,7 +556,7 @@ Returns `request`.
|
|||||||
added: v0.1.17
|
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'
|
### Event: 'checkContinue'
|
||||||
<!-- YAML
|
<!-- 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
|
header names and the values are the respective header values. All header names
|
||||||
are lowercase.
|
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:
|
Example:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
@ -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_
|
*Note*: The object returned by the `querystring.parse()` method _does not_
|
||||||
prototypically extend from the JavaScript `Object`. This means that the
|
prototypically inherit from the JavaScript `Object`. This means that typical
|
||||||
typical `Object` methods such as `obj.toString()`, `obj.hasOwnProperty()`,
|
`Object` methods such as `obj.toString()`, `obj.hasOwnProperty()`, and others
|
||||||
and others are not defined and *will not work*.
|
are not defined and *will not work*.
|
||||||
|
|
||||||
By default, percent-encoded characters within the query string will be assumed
|
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
|
to use UTF-8 encoding. If an alternative character encoding is used, then an
|
||||||
|
@ -43,8 +43,9 @@ const s = http.createServer(common.mustCall((req, res) => {
|
|||||||
switch (test) {
|
switch (test) {
|
||||||
case 'headers':
|
case 'headers':
|
||||||
// Check that header-related functions work before setting any headers
|
// Check that header-related functions work before setting any headers
|
||||||
// eslint-disable-next-line no-restricted-properties
|
const headers = res.getHeaders();
|
||||||
assert.deepEqual(res.getHeaders(), {});
|
const exoticObj = Object.create(null);
|
||||||
|
assert.deepStrictEqual(headers, exoticObj);
|
||||||
assert.deepStrictEqual(res.getHeaderNames(), []);
|
assert.deepStrictEqual(res.getHeaderNames(), []);
|
||||||
assert.deepStrictEqual(res.hasHeader('Connection'), false);
|
assert.deepStrictEqual(res.hasHeader('Connection'), false);
|
||||||
assert.deepStrictEqual(res.getHeader('Connection'), undefined);
|
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');
|
assert.strictEqual(res.getHeader('x-test-header2'), 'testing');
|
||||||
|
|
||||||
const headersCopy = res.getHeaders();
|
const headersCopy = res.getHeaders();
|
||||||
|
assert.strictEqual(Object.getPrototypeOf(headersCopy), null);
|
||||||
// eslint-disable-next-line no-restricted-properties
|
// eslint-disable-next-line no-restricted-properties
|
||||||
assert.deepEqual(headersCopy, {
|
assert.deepEqual(headersCopy, {
|
||||||
'x-test-header': 'testing',
|
'x-test-header': 'testing',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user