@@ -13,10 +13,25 @@ const inspector = require('node:inspector/promises');
13
13
const session = new inspector . Session ( ) ;
14
14
session . connect ( ) ;
15
15
16
+ const requestHeaders = {
17
+ 'accept-language' : 'en-US' ,
18
+ 'Cookie' : [ 'k1=v1' , 'k2=v2' ] ,
19
+ 'age' : 1000 ,
20
+ 'x-header1' : [ 'value1' , 'value2' ]
21
+ } ;
22
+
23
+ const setResponseHeaders = ( res ) => {
24
+ res . setHeader ( 'server' , 'node' ) ;
25
+ res . setHeader ( 'etag' , 12345 ) ;
26
+ res . setHeader ( 'Set-Cookie' , [ 'key1=value1' , 'key2=value2' ] ) ;
27
+ res . setHeader ( 'x-header2' , [ 'value1' , 'value2' ] ) ;
28
+ } ;
29
+
16
30
const httpServer = http . createServer ( ( req , res ) => {
17
31
const path = req . url ;
18
32
switch ( path ) {
19
33
case '/hello-world' :
34
+ setResponseHeaders ( res ) ;
20
35
res . writeHead ( 200 ) ;
21
36
res . end ( 'hello world\n' ) ;
22
37
break ;
@@ -32,6 +47,7 @@ const httpsServer = https.createServer({
32
47
const path = req . url ;
33
48
switch ( path ) {
34
49
case '/hello-world' :
50
+ setResponseHeaders ( res ) ;
35
51
res . writeHead ( 200 ) ;
36
52
res . end ( 'hello world\n' ) ;
37
53
break ;
@@ -53,6 +69,10 @@ const testHttpGet = () => new Promise((resolve, reject) => {
53
69
assert . strictEqual ( params . request . url , 'http://127.0.0.1/hello-world' ) ;
54
70
assert . strictEqual ( params . request . method , 'GET' ) ;
55
71
assert . strictEqual ( typeof params . request . headers , 'object' ) ;
72
+ assert . strictEqual ( params . request . headers [ 'accept-language' ] , 'en-US' ) ;
73
+ assert . strictEqual ( params . request . headers . cookie , 'k1=v1; k2=v2' ) ;
74
+ assert . strictEqual ( params . request . headers . age , '1000' ) ;
75
+ assert . strictEqual ( params . request . headers [ 'x-header1' ] , 'value1, value2' ) ;
56
76
assert . strictEqual ( typeof params . timestamp , 'number' ) ;
57
77
assert . strictEqual ( typeof params . wallTime , 'number' ) ;
58
78
} ) ) ;
@@ -64,6 +84,10 @@ const testHttpGet = () => new Promise((resolve, reject) => {
64
84
assert . strictEqual ( params . response . statusText , 'OK' ) ;
65
85
assert . strictEqual ( params . response . url , 'http://127.0.0.1/hello-world' ) ;
66
86
assert . strictEqual ( typeof params . response . headers , 'object' ) ;
87
+ assert . strictEqual ( params . response . headers . server , 'node' ) ;
88
+ assert . strictEqual ( params . response . headers . etag , '12345' ) ;
89
+ assert . strictEqual ( params . response . headers [ 'set-cookie' ] , 'key1=value1\nkey2=value2' ) ;
90
+ assert . strictEqual ( params . response . headers [ 'x-header2' ] , 'value1, value2' ) ;
67
91
} ) ) ;
68
92
session . on ( 'Network.loadingFinished' , common . mustCall ( ( { params } ) => {
69
93
assert . ok ( params . requestId . startsWith ( 'node-network-event-' ) ) ;
@@ -75,6 +99,7 @@ const testHttpGet = () => new Promise((resolve, reject) => {
75
99
host : '127.0.0.1' ,
76
100
port : httpServer . address ( ) . port ,
77
101
path : '/hello-world' ,
102
+ headers : requestHeaders
78
103
} , common . mustCall ( ) ) ;
79
104
} ) ;
80
105
@@ -84,6 +109,10 @@ const testHttpsGet = () => new Promise((resolve, reject) => {
84
109
assert . strictEqual ( params . request . url , 'https://127.0.0.1/hello-world' ) ;
85
110
assert . strictEqual ( params . request . method , 'GET' ) ;
86
111
assert . strictEqual ( typeof params . request . headers , 'object' ) ;
112
+ assert . strictEqual ( params . request . headers [ 'accept-language' ] , 'en-US' ) ;
113
+ assert . strictEqual ( params . request . headers . cookie , 'k1=v1; k2=v2' ) ;
114
+ assert . strictEqual ( params . request . headers . age , '1000' ) ;
115
+ assert . strictEqual ( params . request . headers [ 'x-header1' ] , 'value1, value2' ) ;
87
116
assert . strictEqual ( typeof params . timestamp , 'number' ) ;
88
117
assert . strictEqual ( typeof params . wallTime , 'number' ) ;
89
118
} ) ) ;
@@ -95,6 +124,10 @@ const testHttpsGet = () => new Promise((resolve, reject) => {
95
124
assert . strictEqual ( params . response . statusText , 'OK' ) ;
96
125
assert . strictEqual ( params . response . url , 'https://127.0.0.1/hello-world' ) ;
97
126
assert . strictEqual ( typeof params . response . headers , 'object' ) ;
127
+ assert . strictEqual ( params . response . headers . server , 'node' ) ;
128
+ assert . strictEqual ( params . response . headers . etag , '12345' ) ;
129
+ assert . strictEqual ( params . response . headers [ 'set-cookie' ] , 'key1=value1\nkey2=value2' ) ;
130
+ assert . strictEqual ( params . response . headers [ 'x-header2' ] , 'value1, value2' ) ;
98
131
} ) ) ;
99
132
session . on ( 'Network.loadingFinished' , common . mustCall ( ( { params } ) => {
100
133
assert . ok ( params . requestId . startsWith ( 'node-network-event-' ) ) ;
@@ -107,6 +140,7 @@ const testHttpsGet = () => new Promise((resolve, reject) => {
107
140
port : httpsServer . address ( ) . port ,
108
141
path : '/hello-world' ,
109
142
rejectUnauthorized : false ,
143
+ headers : requestHeaders ,
110
144
} , common . mustCall ( ) ) ;
111
145
} ) ;
112
146
0 commit comments