@@ -4,40 +4,92 @@ const common = require('../common');
44if ( ! common . hasCrypto )
55 common . skip ( 'missing crypto' ) ;
66const 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- const returnVal = response . writeHead ( 200 , [
16- [ 'foo' , 'bar' ] ,
17- [ 'ABC' , 123 ] ,
18- ] ) ;
19- assert . strictEqual ( returnVal , response ) ;
20- response . end ( common . mustCall ( ( ) => { server . close ( ) ; } ) ) ;
7+ const http2 = require ( 'http2' ) ;
8+
9+ // Http2ServerResponse.writeHead should support arrays and nested arrays
10+
11+ {
12+ const server = http2 . createServer ( ) ;
13+ server . listen ( 0 , common . mustCall ( ( ) => {
14+ const port = server . address ( ) . port ;
15+
16+ server . once ( 'request' , common . mustCall ( ( request , response ) => {
17+ const returnVal = response . writeHead ( 200 , [
18+ [ 'foo' , 'bar' ] ,
19+ [ 'ABC' , 123 ] ,
20+ ] ) ;
21+ assert . strictEqual ( returnVal , response ) ;
22+ response . end ( common . mustCall ( ( ) => { server . close ( ) ; } ) ) ;
23+ } ) ) ;
24+
25+ const client = http2 . connect ( `http://localhost:${ port } ` , common . mustCall ( ( ) => {
26+ const request = client . request ( ) ;
27+
28+ request . on ( 'response' , common . mustCall ( ( headers ) => {
29+ assert . strictEqual ( headers . foo , 'bar' ) ;
30+ assert . strictEqual ( headers . abc , '123' ) ;
31+ assert . strictEqual ( headers [ ':status' ] , 200 ) ;
32+ } , 1 ) ) ;
33+ request . on ( 'end' , common . mustCall ( ( ) => {
34+ client . close ( ) ;
35+ } ) ) ;
36+ request . end ( ) ;
37+ request . resume ( ) ;
38+ } ) ) ;
2139 } ) ) ;
40+ }
41+
42+ {
43+ const server = http2 . createServer ( ) ;
44+ server . listen ( 0 , common . mustCall ( ( ) => {
45+ const port = server . address ( ) . port ;
46+
47+ server . once ( 'request' , common . mustCall ( ( request , response ) => {
48+ const returnVal = response . writeHead ( 200 , [ 'foo' , 'bar' , 'ABC' , 123 ] ) ;
49+ assert . strictEqual ( returnVal , response ) ;
50+ response . end ( common . mustCall ( ( ) => { server . close ( ) ; } ) ) ;
51+ } ) ) ;
52+
53+ const client = http2 . connect ( `http://localhost:${ port } ` , common . mustCall ( ( ) => {
54+ const request = client . request ( ) ;
55+
56+ request . on ( 'response' , common . mustCall ( ( headers ) => {
57+ assert . strictEqual ( headers . foo , 'bar' ) ;
58+ assert . strictEqual ( headers . abc , '123' ) ;
59+ assert . strictEqual ( headers [ ':status' ] , 200 ) ;
60+ } , 1 ) ) ;
61+ request . on ( 'end' , common . mustCall ( ( ) => {
62+ client . close ( ) ;
63+ } ) ) ;
64+ request . end ( ) ;
65+ request . resume ( ) ;
66+ } ) ) ;
67+ } ) ) ;
68+ }
69+
70+ {
71+ const server = http2 . createServer ( ) ;
72+ server . listen ( 0 , common . mustCall ( ( ) => {
73+ const port = server . address ( ) . port ;
74+
75+ server . once ( 'request' , common . mustCall ( ( request , response ) => {
76+ try {
77+ response . writeHead ( 200 , [ 'foo' , 'bar' , 'ABC' , 123 , 'extra' ] ) ;
78+ } catch ( err ) {
79+ assert . strictEqual ( err . code , 'ERR_INVALID_ARG_VALUE' ) ;
80+ }
81+
82+ response . end ( common . mustCall ( ( ) => { server . close ( ) ; } ) ) ;
83+ } ) ) ;
84+
85+ const client = http2 . connect ( `http://localhost:${ port } ` , common . mustCall ( ( ) => {
86+ const request = client . request ( ) ;
2287
23- const url = `http://localhost:${ port } ` ;
24- const client = h2 . connect ( url , common . mustCall ( ( ) => {
25- const headers = {
26- ':path' : '/' ,
27- ':method' : 'GET' ,
28- ':scheme' : 'http' ,
29- ':authority' : `localhost:${ port } `
30- } ;
31- const request = client . request ( headers ) ;
32- request . on ( 'response' , common . mustCall ( ( headers ) => {
33- assert . strictEqual ( headers . foo , 'bar' ) ;
34- assert . strictEqual ( headers . abc , '123' ) ;
35- assert . strictEqual ( headers [ ':status' ] , 200 ) ;
36- } , 1 ) ) ;
37- request . on ( 'end' , common . mustCall ( ( ) => {
38- client . close ( ) ;
88+ request . on ( 'end' , common . mustCall ( ( ) => {
89+ client . close ( ) ;
90+ } ) ) ;
91+ request . end ( ) ;
92+ request . resume ( ) ;
3993 } ) ) ;
40- request . end ( ) ;
41- request . resume ( ) ;
4294 } ) ) ;
43- } ) ) ;
95+ }
0 commit comments