@@ -1273,14 +1273,11 @@ describe('WebSocket', () => {
1273
1273
ws . close ( ) ;
1274
1274
} ) ;
1275
1275
1276
- const ws = new WebSocket (
1277
- `wss://localhost:${ server . address ( ) . port } ` ,
1278
- {
1279
- auth : 'foo:bar' ,
1280
- followRedirects : true ,
1281
- rejectUnauthorized : false
1282
- }
1283
- ) ;
1276
+ const ws = new WebSocket ( `wss://localhost:${ port } ` , {
1277
+ auth : 'foo:bar' ,
1278
+ followRedirects : true ,
1279
+ rejectUnauthorized : false
1280
+ } ) ;
1284
1281
1285
1282
assert . strictEqual (
1286
1283
ws . _req . getHeader ( 'Authorization' ) ,
@@ -1297,13 +1294,7 @@ describe('WebSocket', () => {
1297
1294
} ) ;
1298
1295
} ) ;
1299
1296
1300
- it ( 'drops the Authorization, and Cookie headers' , ( done ) => {
1301
- const headers = {
1302
- authorization : 'Basic Zm9vOmJhcg==' ,
1303
- cookie : 'foo=bar' ,
1304
- host : 'foo'
1305
- } ;
1306
-
1297
+ it ( 'drops the Authorization and Cookie headers' , ( done ) => {
1307
1298
const httpServer = http . createServer ( ) ;
1308
1299
const httpsServer = https . createServer ( {
1309
1300
cert : fs . readFileSync ( 'test/fixtures/certificate.pem' ) ,
@@ -1322,20 +1313,27 @@ describe('WebSocket', () => {
1322
1313
) ;
1323
1314
} ) ;
1324
1315
1316
+ const headers = {
1317
+ authorization : 'Basic Zm9vOmJhcg==' ,
1318
+ cookie : 'foo=bar' ,
1319
+ host : 'foo'
1320
+ } ;
1321
+
1325
1322
const wss = new WebSocket . Server ( { server : httpServer } ) ;
1326
1323
1327
1324
wss . on ( 'connection' , ( ws , req ) => {
1328
1325
assert . strictEqual ( req . headers . authorization , undefined ) ;
1329
1326
assert . strictEqual ( req . headers . cookie , undefined ) ;
1330
- assert . strictEqual ( req . headers . host , 'foo' ) ;
1327
+ assert . strictEqual ( req . headers . host , headers . host ) ;
1331
1328
1332
1329
ws . close ( ) ;
1333
1330
} ) ;
1334
1331
1335
- const ws = new WebSocket (
1336
- `wss://localhost:${ server . address ( ) . port } ` ,
1337
- { headers, followRedirects : true , rejectUnauthorized : false }
1338
- ) ;
1332
+ const ws = new WebSocket ( `wss://localhost:${ port } ` , {
1333
+ followRedirects : true ,
1334
+ headers,
1335
+ rejectUnauthorized : false
1336
+ } ) ;
1339
1337
1340
1338
const firstRequest = ws . _req ;
1341
1339
@@ -1362,12 +1360,6 @@ describe('WebSocket', () => {
1362
1360
1363
1361
describe ( "If there is at least one 'redirect' event listener" , ( ) => {
1364
1362
it ( 'does not drop any headers by default' , ( done ) => {
1365
- const headers = {
1366
- authorization : 'Basic Zm9vOmJhcg==' ,
1367
- cookie : 'foo=bar' ,
1368
- host : 'foo'
1369
- } ;
1370
-
1371
1363
const httpServer = http . createServer ( ) ;
1372
1364
const httpsServer = https . createServer ( {
1373
1365
cert : fs . readFileSync ( 'test/fixtures/certificate.pem' ) ,
@@ -1386,6 +1378,12 @@ describe('WebSocket', () => {
1386
1378
) ;
1387
1379
} ) ;
1388
1380
1381
+ const headers = {
1382
+ authorization : 'Basic Zm9vOmJhcg==' ,
1383
+ cookie : 'foo=bar' ,
1384
+ host : 'foo'
1385
+ } ;
1386
+
1389
1387
const wss = new WebSocket . Server ( { server : httpServer } ) ;
1390
1388
1391
1389
wss . on ( 'connection' , ( ws , req ) => {
@@ -1399,10 +1397,11 @@ describe('WebSocket', () => {
1399
1397
ws . close ( ) ;
1400
1398
} ) ;
1401
1399
1402
- const ws = new WebSocket (
1403
- `wss://localhost:${ server . address ( ) . port } ` ,
1404
- { headers, followRedirects : true , rejectUnauthorized : false }
1405
- ) ;
1400
+ const ws = new WebSocket ( `wss://localhost:${ port } ` , {
1401
+ followRedirects : true ,
1402
+ headers,
1403
+ rejectUnauthorized : false
1404
+ } ) ;
1406
1405
1407
1406
const firstRequest = ws . _req ;
1408
1407
@@ -1478,7 +1477,7 @@ describe('WebSocket', () => {
1478
1477
} ) ;
1479
1478
} ) ;
1480
1479
1481
- it ( 'drops the Authorization, Cookie, and Host headers' , ( done ) => {
1480
+ it ( 'drops the Authorization, Cookie and Host headers' , ( done ) => {
1482
1481
const wss = new WebSocket . Server ( { port : 0 } , ( ) => {
1483
1482
const port = wss . address ( ) . port ;
1484
1483
@@ -1489,24 +1488,28 @@ describe('WebSocket', () => {
1489
1488
) ;
1490
1489
} ) ;
1491
1490
1491
+ const headers = {
1492
+ authorization : 'Basic Zm9vOmJhcg==' ,
1493
+ cookie : 'foo=bar' ,
1494
+ host : 'foo'
1495
+ } ;
1496
+
1492
1497
const ws = new WebSocket (
1493
1498
`ws://localhost:${ server . address ( ) . port } ` ,
1494
- {
1495
- headers : {
1496
- Authorization : 'Basic Zm9vOmJhcg==' ,
1497
- Cookie : 'foo=bar' ,
1498
- Host : 'foo'
1499
- } ,
1500
- followRedirects : true
1501
- }
1499
+ { followRedirects : true , headers }
1502
1500
) ;
1503
1501
1502
+ const firstRequest = ws . _req ;
1503
+
1504
1504
assert . strictEqual (
1505
- ws . _req . getHeader ( 'Authorization' ) ,
1506
- 'Basic Zm9vOmJhcg=='
1505
+ firstRequest . getHeader ( 'Authorization' ) ,
1506
+ headers . authorization
1507
1507
) ;
1508
- assert . strictEqual ( ws . _req . getHeader ( 'Cookie' ) , 'foo=bar' ) ;
1509
- assert . strictEqual ( ws . _req . getHeader ( 'Host' ) , 'foo' ) ;
1508
+ assert . strictEqual (
1509
+ firstRequest . getHeader ( 'Cookie' ) ,
1510
+ headers . cookie
1511
+ ) ;
1512
+ assert . strictEqual ( firstRequest . getHeader ( 'Host' ) , headers . host ) ;
1510
1513
1511
1514
ws . on ( 'close' , ( code ) => {
1512
1515
assert . strictEqual ( code , 1005 ) ;
@@ -1524,6 +1527,7 @@ describe('WebSocket', () => {
1524
1527
req . headers . host ,
1525
1528
`localhost:${ wss . address ( ) . port } `
1526
1529
) ;
1530
+
1527
1531
ws . close ( ) ;
1528
1532
} ) ;
1529
1533
} ) ;
@@ -1549,7 +1553,7 @@ describe('WebSocket', () => {
1549
1553
1550
1554
const ws = new WebSocket (
1551
1555
`ws://localhost:${ server . address ( ) . port } ` ,
1552
- { headers , followRedirects : true }
1556
+ { followRedirects : true , headers }
1553
1557
) ;
1554
1558
1555
1559
const firstRequest = ws . _req ;
@@ -1643,8 +1647,8 @@ describe('WebSocket', () => {
1643
1647
} ;
1644
1648
1645
1649
const ws = new WebSocket ( `ws://localhost:${ server . address ( ) . port } ` , {
1646
- headers ,
1647
- followRedirects : true
1650
+ followRedirects : true ,
1651
+ headers
1648
1652
} ) ;
1649
1653
1650
1654
ws . on ( 'redirect' , ( url , req ) => {
0 commit comments