File tree 2 files changed +50
-2
lines changed
2 files changed +50
-2
lines changed Original file line number Diff line number Diff line change @@ -574,10 +574,16 @@ class Http2ServerResponse extends Stream {
574
574
if ( headers === undefined && typeof statusMessage === 'object' )
575
575
headers = statusMessage ;
576
576
577
- if ( typeof headers === 'object' ) {
577
+ var i ;
578
+ if ( Array . isArray ( headers ) ) {
579
+ for ( i = 0 ; i < headers . length ; i ++ ) {
580
+ const header = headers [ i ] ;
581
+ this [ kSetHeader ] ( header [ 0 ] , header [ 1 ] ) ;
582
+ }
583
+ } else if ( typeof headers === 'object' ) {
578
584
const keys = Object . keys ( headers ) ;
579
585
let key = '' ;
580
- for ( var i = 0 ; i < keys . length ; i ++ ) {
586
+ for ( i = 0 ; i < keys . length ; i ++ ) {
581
587
key = keys [ i ] ;
582
588
this [ kSetHeader ] ( key , headers [ key ] ) ;
583
589
}
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ const common = require ( '../common' ) ;
4
+ if ( ! common . hasCrypto )
5
+ common . skip ( 'missing crypto' ) ;
6
+ const assert = require ( 'assert' ) ;
7
+ const h2 = require ( 'http2' ) ;
8
+
9
+ // Http2ServerResponse.writeHead should support nested arrays
10
+
11
+ const server = h2 . createServer ( ) ;
12
+ server . listen ( 0 , common . mustCall ( ( ) => {
13
+ const port = server . address ( ) . port ;
14
+ server . once ( 'request' , common . mustCall ( ( request , response ) => {
15
+ response . writeHead ( 200 , [
16
+ [ 'foo' , 'bar' ] ,
17
+ [ 'ABC' , 123 ]
18
+ ] ) ;
19
+ response . end ( common . mustCall ( ( ) => { server . close ( ) ; } ) ) ;
20
+ } ) ) ;
21
+
22
+ const url = `http://localhost:${ port } ` ;
23
+ const client = h2 . connect ( url , common . mustCall ( ( ) => {
24
+ const headers = {
25
+ ':path' : '/' ,
26
+ ':method' : 'GET' ,
27
+ ':scheme' : 'http' ,
28
+ ':authority' : `localhost:${ port } `
29
+ } ;
30
+ const request = client . request ( headers ) ;
31
+ request . on ( 'response' , common . mustCall ( ( headers ) => {
32
+ assert . strictEqual ( headers . foo , 'bar' ) ;
33
+ assert . strictEqual ( headers . abc , '123' ) ;
34
+ assert . strictEqual ( headers [ ':status' ] , 200 ) ;
35
+ } , 1 ) ) ;
36
+ request . on ( 'end' , common . mustCall ( ( ) => {
37
+ client . close ( ) ;
38
+ } ) ) ;
39
+ request . end ( ) ;
40
+ request . resume ( ) ;
41
+ } ) ) ;
42
+ } ) ) ;
You can’t perform that action at this time.
0 commit comments