Skip to content
Permalink
Browse files

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 <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 7, 2017
1 parent 57a08e2 commit e1cabf6fbdbcfe223a9a46ffe6730e73719d5ab5
Showing with 13 additions and 6 deletions.
  1. +6 −1 doc/api/http.md
  2. +3 −3 doc/api/querystring.md
  3. +4 −2 test/parallel/test-http-mutable-headers.js
@@ -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
@@ -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
@@ -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',

0 comments on commit e1cabf6

Please sign in to comment.
You can’t perform that action at this time.