@@ -24,6 +24,9 @@ const common = require('../common');
2424if ( ! common . hasCrypto )
2525 common . skip ( 'missing crypto' ) ;
2626
27+ // This test ensures that the data received through tls over http tunnel
28+ // is same as what is sent.
29+
2730const assert = require ( 'assert' ) ;
2831const https = require ( 'https' ) ;
2932const net = require ( 'net' ) ;
@@ -37,21 +40,21 @@ const cert = fixtures.readKey('agent1-cert.pem');
3740
3841const options = { key, cert } ;
3942
40- const server = https . createServer ( options , function ( req , res ) {
43+ const server = https . createServer ( options , common . mustCall ( ( req , res ) => {
4144 console . log ( 'SERVER: got request' ) ;
4245 res . writeHead ( 200 , {
4346 'content-type' : 'text/plain'
4447 } ) ;
4548 console . log ( 'SERVER: sending response' ) ;
4649 res . end ( 'hello world\n' ) ;
47- } ) ;
50+ } ) ) ;
4851
49- const proxy = net . createServer ( function ( clientSocket ) {
52+ const proxy = net . createServer ( ( clientSocket ) => {
5053 console . log ( 'PROXY: got a client connection' ) ;
5154
5255 let serverSocket = null ;
5356
54- clientSocket . on ( 'data' , function ( chunk ) {
57+ clientSocket . on ( 'data' , ( chunk ) => {
5558 if ( ! serverSocket ) {
5659 // Verify the CONNECT request
5760 assert . strictEqual ( `CONNECT localhost:${ server . address ( ) . port } ` +
@@ -65,39 +68,39 @@ const proxy = net.createServer(function(clientSocket) {
6568 console . log ( 'PROXY: creating a tunnel' ) ;
6669
6770 // create the tunnel
68- serverSocket = net . connect ( server . address ( ) . port , function ( ) {
71+ serverSocket = net . connect ( server . address ( ) . port , common . mustCall ( ( ) => {
6972 console . log ( 'PROXY: replying to client CONNECT request' ) ;
7073
7174 // Send the response
7275 clientSocket . write ( 'HTTP/1.1 200 OK\r\nProxy-Connections: keep' +
73- '-alive\r\nConnections: keep-alive\r\nVia: ' +
74- `localhost:${ proxy . address ( ) . port } \r\n\r\n` ) ;
75- } ) ;
76+ '-alive\r\nConnections: keep-alive\r\nVia: ' +
77+ `localhost:${ proxy . address ( ) . port } \r\n\r\n` ) ;
78+ } ) ) ;
7679
77- serverSocket . on ( 'data' , function ( chunk ) {
80+ serverSocket . on ( 'data' , ( chunk ) => {
7881 clientSocket . write ( chunk ) ;
7982 } ) ;
8083
81- serverSocket . on ( 'end' , function ( ) {
84+ serverSocket . on ( 'end' , common . mustCall ( ( ) => {
8285 clientSocket . destroy ( ) ;
83- } ) ;
86+ } ) ) ;
8487 } else {
8588 serverSocket . write ( chunk ) ;
8689 }
8790 } ) ;
8891
89- clientSocket . on ( 'end' , function ( ) {
92+ clientSocket . on ( 'end' , ( ) => {
9093 serverSocket . destroy ( ) ;
9194 } ) ;
9295} ) ;
9396
9497server . listen ( 0 ) ;
9598
96- proxy . listen ( 0 , function ( ) {
99+ proxy . listen ( 0 , common . mustCall ( ( ) => {
97100 console . log ( 'CLIENT: Making CONNECT request' ) ;
98101
99102 const req = http . request ( {
100- port : this . address ( ) . port ,
103+ port : proxy . address ( ) . port ,
101104 method : 'CONNECT' ,
102105 path : `localhost:${ server . address ( ) . port } ` ,
103106 headers : {
@@ -117,7 +120,7 @@ proxy.listen(0, function() {
117120
118121 function onUpgrade ( res , socket , head ) {
119122 // Hacky.
120- process . nextTick ( function ( ) {
123+ process . nextTick ( ( ) => {
121124 onConnect ( res , socket , head ) ;
122125 } ) ;
123126 }
@@ -145,29 +148,29 @@ proxy.listen(0, function() {
145148 socket : socket , // reuse the socket
146149 agent : false ,
147150 rejectUnauthorized : false
148- } , function ( res ) {
151+ } , ( res ) => {
149152 assert . strictEqual ( 200 , res . statusCode ) ;
150153
151- res . on ( 'data' , function ( chunk ) {
154+ res . on ( 'data' , common . mustCall ( ( chunk ) => {
152155 assert . strictEqual ( 'hello world\n' , chunk . toString ( ) ) ;
153156 console . log ( 'CLIENT: got HTTPS response' ) ;
154157 gotRequest = true ;
155- } ) ;
158+ } ) ) ;
156159
157- res . on ( 'end' , function ( ) {
160+ res . on ( 'end' , common . mustCall ( ( ) => {
158161 proxy . close ( ) ;
159162 server . close ( ) ;
160- } ) ;
161- } ) . on ( 'error' , function ( er ) {
163+ } ) ) ;
164+ } ) . on ( 'error' , ( er ) => {
162165 // We're ok with getting ECONNRESET in this test, but it's
163166 // timing-dependent, and thus unreliable. Any other errors
164167 // are just failures, though.
165168 if ( er . code !== 'ECONNRESET' )
166169 throw er ;
167170 } ) . end ( ) ;
168171 }
169- } ) ;
172+ } ) ) ;
170173
171- process . on ( 'exit' , function ( ) {
174+ process . on ( 'exit' , ( ) => {
172175 assert . ok ( gotRequest ) ;
173176} ) ;
0 commit comments