Skip to content

Commit

Permalink
doc, test: add note to response.getHeaders
Browse files Browse the repository at this point in the history
* also correct language for the same note for querystring.parse
* add assertions for said note

PR-URL: nodejs#12887
Fixes: nodejs#12885
Refs: nodejs#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>
  • Loading branch information
refack committed May 10, 2017
1 parent 57a08e2 commit e1cabf6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
7 changes: 6 additions & 1 deletion doc/api/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions doc/api/querystring.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions test/parallel/test-http-mutable-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit e1cabf6

Please sign in to comment.