diff options
author | Gerhard Stoebich <deb2001-github@yahoo.de> | 2018-06-15 23:37:46 +0200 |
---|---|---|
committer | Matteo Collina <hello@matteocollina.com> | 2018-07-05 14:56:54 +0200 |
commit | d4966a15cb944a07caa9ca653565fb5c585f8f0d (patch) | |
tree | b54f6d7ccd2ccc94db2c0f1910fa00b5c11f256b /test | |
parent | e021ca28ea6dc87094e97afd3aec6fd8cecd571d (diff) | |
download | android-node-v8-d4966a15cb944a07caa9ca653565fb5c585f8f0d.tar.gz android-node-v8-d4966a15cb944a07caa9ca653565fb5c585f8f0d.tar.bz2 android-node-v8-d4966a15cb944a07caa9ca653565fb5c585f8f0d.zip |
http2: pass incoming set-cookie header as array
Incoming set-cookie headers should be passed to user as array like in
http module.
Besides improving compatibility between http and http2 it avoids the
need to check if the type is an array or not in user code.
PR-URL: https://github.com/nodejs/node/pull/21360
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-http2-util-headers-list.js | 44 |
1 files changed, 41 insertions, 3 deletions
diff --git a/test/parallel/test-http2-util-headers-list.js b/test/parallel/test-http2-util-headers-list.js index 772e9c8679..7b83883553 100644 --- a/test/parallel/test-http2-util-headers-list.js +++ b/test/parallel/test-http2-util-headers-list.js @@ -1,14 +1,14 @@ // Flags: --expose-internals 'use strict'; -// Tests the internal utility function that is used to prepare headers -// to pass to the internal binding layer. +// Tests the internal utility functions that are used to prepare headers +// to pass to the internal binding layer and to build a header object. const common = require('../common'); if (!common.hasCrypto) common.skip('missing crypto'); const assert = require('assert'); -const { mapToHeaders } = require('internal/http2/util'); +const { mapToHeaders, toHeaderObject } = require('internal/http2/util'); const { HTTP2_HEADER_STATUS, @@ -305,3 +305,41 @@ common.expectsError({ assert(!(mapToHeaders({ te: 'trailers' }) instanceof Error)); assert(!(mapToHeaders({ te: ['trailers'] }) instanceof Error)); + + +{ + const rawHeaders = [ + ':status', '200', + 'cookie', 'foo', + 'set-cookie', 'sc1', + 'age', '10', + 'x-multi', 'first' + ]; + const headers = toHeaderObject(rawHeaders); + assert.strictEqual(headers[':status'], 200); + assert.strictEqual(headers.cookie, 'foo'); + assert.deepStrictEqual(headers['set-cookie'], ['sc1']); + assert.strictEqual(headers.age, '10'); + assert.strictEqual(headers['x-multi'], 'first'); +} + +{ + const rawHeaders = [ + ':status', '200', + ':status', '400', + 'cookie', 'foo', + 'cookie', 'bar', + 'set-cookie', 'sc1', + 'set-cookie', 'sc2', + 'age', '10', + 'age', '20', + 'x-multi', 'first', + 'x-multi', 'second' + ]; + const headers = toHeaderObject(rawHeaders); + assert.strictEqual(headers[':status'], 200); + assert.strictEqual(headers.cookie, 'foo; bar'); + assert.deepStrictEqual(headers['set-cookie'], ['sc1', 'sc2']); + assert.strictEqual(headers.age, '10'); + assert.strictEqual(headers['x-multi'], 'first, second'); +} |