|
1 | 1 | // Flags: --expose-internals
|
2 | 2 | 'use strict';
|
3 | 3 |
|
4 |
| -// Tests the internal utility function that is used to prepare headers |
5 |
| -// to pass to the internal binding layer. |
| 4 | +// Tests the internal utility functions that are used to prepare headers |
| 5 | +// to pass to the internal binding layer and to build a header object. |
6 | 6 |
|
7 | 7 | const common = require('../common');
|
8 | 8 | if (!common.hasCrypto)
|
9 | 9 | common.skip('missing crypto');
|
10 | 10 | const assert = require('assert');
|
11 |
| -const { mapToHeaders } = require('internal/http2/util'); |
| 11 | +const { mapToHeaders, toHeaderObject } = require('internal/http2/util'); |
12 | 12 |
|
13 | 13 | const {
|
14 | 14 | HTTP2_HEADER_STATUS,
|
@@ -302,3 +302,41 @@ common.expectsError({
|
302 | 302 |
|
303 | 303 | assert(!(mapToHeaders({ te: 'trailers' }) instanceof Error));
|
304 | 304 | assert(!(mapToHeaders({ te: ['trailers'] }) instanceof Error));
|
| 305 | + |
| 306 | + |
| 307 | +{ |
| 308 | + const rawHeaders = [ |
| 309 | + ':status', '200', |
| 310 | + 'cookie', 'foo', |
| 311 | + 'set-cookie', 'sc1', |
| 312 | + 'age', '10', |
| 313 | + 'x-multi', 'first' |
| 314 | + ]; |
| 315 | + const headers = toHeaderObject(rawHeaders); |
| 316 | + assert.strictEqual(headers[':status'], 200); |
| 317 | + assert.strictEqual(headers.cookie, 'foo'); |
| 318 | + assert.deepStrictEqual(headers['set-cookie'], ['sc1']); |
| 319 | + assert.strictEqual(headers.age, '10'); |
| 320 | + assert.strictEqual(headers['x-multi'], 'first'); |
| 321 | +} |
| 322 | + |
| 323 | +{ |
| 324 | + const rawHeaders = [ |
| 325 | + ':status', '200', |
| 326 | + ':status', '400', |
| 327 | + 'cookie', 'foo', |
| 328 | + 'cookie', 'bar', |
| 329 | + 'set-cookie', 'sc1', |
| 330 | + 'set-cookie', 'sc2', |
| 331 | + 'age', '10', |
| 332 | + 'age', '20', |
| 333 | + 'x-multi', 'first', |
| 334 | + 'x-multi', 'second' |
| 335 | + ]; |
| 336 | + const headers = toHeaderObject(rawHeaders); |
| 337 | + assert.strictEqual(headers[':status'], 200); |
| 338 | + assert.strictEqual(headers.cookie, 'foo; bar'); |
| 339 | + assert.deepStrictEqual(headers['set-cookie'], ['sc1', 'sc2']); |
| 340 | + assert.strictEqual(headers.age, '10'); |
| 341 | + assert.strictEqual(headers['x-multi'], 'first, second'); |
| 342 | +} |
0 commit comments