summaryrefslogtreecommitdiff
path: root/test/parallel/test-http-mutable-headers.js
diff options
context:
space:
mode:
authorBrian White <mscdex@mscdex.net>2017-01-14 09:39:58 -0500
committerBrian White <mscdex@mscdex.net>2017-02-20 16:50:43 -0500
commit3e6f1032a4fdb8ca7fba02c7d2103fba68c0ee1f (patch)
treedb3dd9e8c59bc2f65ad427282a1e2801d7c6331a /test/parallel/test-http-mutable-headers.js
parent52ddb41c6006cfae93099e628aa040371e0512de (diff)
downloadandroid-node-v8-3e6f1032a4fdb8ca7fba02c7d2103fba68c0ee1f.tar.gz
android-node-v8-3e6f1032a4fdb8ca7fba02c7d2103fba68c0ee1f.tar.bz2
android-node-v8-3e6f1032a4fdb8ca7fba02c7d2103fba68c0ee1f.zip
http: add new functions to OutgoingMessage
PR-URL: https://github.com/nodejs/node/pull/10805 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Diffstat (limited to 'test/parallel/test-http-mutable-headers.js')
-rw-r--r--test/parallel/test-http-mutable-headers.js46
1 files changed, 45 insertions, 1 deletions
diff --git a/test/parallel/test-http-mutable-headers.js b/test/parallel/test-http-mutable-headers.js
index c2c573682e..d78632c214 100644
--- a/test/parallel/test-http-mutable-headers.js
+++ b/test/parallel/test-http-mutable-headers.js
@@ -21,6 +21,13 @@ const cookies = [
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(), {});
+ assert.deepStrictEqual(res.getHeaderNames(), []);
+ assert.deepStrictEqual(res.hasHeader('Connection'), false);
+ assert.deepStrictEqual(res.getHeader('Connection'), undefined);
+
assert.throws(() => {
res.setHeader();
}, /^TypeError: Header name must be a valid HTTP Token \["undefined"\]$/);
@@ -34,15 +41,52 @@ const s = http.createServer(common.mustCall((req, res) => {
res.removeHeader();
}, /^TypeError: "name" argument must be a string$/);
+ const arrayValues = [1, 2, 3];
res.setHeader('x-test-header', 'testing');
res.setHeader('X-TEST-HEADER2', 'testing');
res.setHeader('set-cookie', cookies);
- res.setHeader('x-test-array-header', [1, 2, 3]);
+ res.setHeader('x-test-array-header', arrayValues);
assert.strictEqual(res.getHeader('x-test-header'), 'testing');
assert.strictEqual(res.getHeader('x-test-header2'), 'testing');
+ const headersCopy = res.getHeaders();
+ // eslint-disable-next-line no-restricted-properties
+ assert.deepEqual(headersCopy, {
+ 'x-test-header': 'testing',
+ 'x-test-header2': 'testing',
+ 'set-cookie': cookies,
+ 'x-test-array-header': arrayValues
+ });
+ // eslint-disable-next-line no-restricted-properties
+ assert.deepEqual(headersCopy['set-cookie'], cookies);
+ assert.strictEqual(headersCopy['x-test-array-header'], arrayValues);
+
+ assert.deepStrictEqual(res.getHeaderNames(),
+ ['x-test-header', 'x-test-header2',
+ 'set-cookie', 'x-test-array-header']);
+
+ assert.strictEqual(res.hasHeader('x-test-header2'), true);
+ assert.strictEqual(res.hasHeader('X-TEST-HEADER2'), true);
+ assert.strictEqual(res.hasHeader('X-Test-Header2'), true);
+ assert.throws(() => {
+ res.hasHeader();
+ }, /^TypeError: "name" argument must be a string$/);
+ assert.throws(() => {
+ res.hasHeader(null);
+ }, /^TypeError: "name" argument must be a string$/);
+ assert.throws(() => {
+ res.hasHeader(true);
+ }, /^TypeError: "name" argument must be a string$/);
+ assert.throws(() => {
+ res.hasHeader({ toString: () => 'X-TEST-HEADER2' });
+ }, /^TypeError: "name" argument must be a string$/);
+
res.removeHeader('x-test-header2');
+
+ assert.strictEqual(res.hasHeader('x-test-header2'), false);
+ assert.strictEqual(res.hasHeader('X-TEST-HEADER2'), false);
+ assert.strictEqual(res.hasHeader('X-Test-Header2'), false);
break;
case 'contentLength':