|
1 | 1 | 'use strict'; |
2 | 2 | constcommon=require('../common'); |
3 | | -varassert=require('assert'); |
4 | | -varhttp=require('http'); |
| 3 | +constassert=require('assert'); |
| 4 | +consthttp=require('http'); |
5 | 5 |
|
6 | | -varserverGotConnect=false; |
7 | | -varclientGotConnect=false; |
| 6 | +constserver=http.createServer(common.fail); |
8 | 7 |
|
9 | | -varserver=http.createServer(common.fail); |
10 | | -server.on('connect',function(req,socket,firstBodyChunk){ |
11 | | -assert.equal(req.method,'CONNECT'); |
12 | | -assert.equal(req.url,'google.com:443'); |
13 | | -console.error('Server got CONNECT request'); |
14 | | -serverGotConnect=true; |
| 8 | +server.on('connect',common.mustCall((req,socket,firstBodyChunk)=>{ |
| 9 | +assert.strictEqual(req.method,'CONNECT'); |
| 10 | +assert.strictEqual(req.url,'google.com:443'); |
15 | 11 |
|
16 | 12 | socket.write('HTTP/1.1 200 Connection established\r\n\r\n'); |
17 | 13 |
|
18 | | -vardata=firstBodyChunk.toString(); |
19 | | -socket.on('data',function(buf){ |
| 14 | +letdata=firstBodyChunk.toString(); |
| 15 | +socket.on('data',(buf)=>{ |
20 | 16 | data+=buf.toString(); |
21 | 17 | }); |
22 | | -socket.on('end',function(){ |
| 18 | + |
| 19 | +socket.on('end',common.mustCall(()=>{ |
23 | 20 | socket.end(data); |
24 | | -}); |
25 | | -}); |
26 | | -server.listen(0,function(){ |
27 | | -varreq=http.request({ |
| 21 | +})); |
| 22 | +})); |
| 23 | + |
| 24 | +server.listen(0,common.mustCall(function(){ |
| 25 | +constreq=http.request({ |
28 | 26 | port: this.address().port, |
29 | 27 | method: 'CONNECT', |
30 | 28 | path: 'google.com:443' |
31 | 29 | },common.fail); |
32 | 30 |
|
33 | | -varclientRequestClosed=false; |
34 | | -req.on('close',function(){ |
35 | | -clientRequestClosed=true; |
36 | | -}); |
37 | | - |
38 | | -req.on('connect',function(res,socket,firstBodyChunk){ |
39 | | -console.error('Client got CONNECT request'); |
40 | | -clientGotConnect=true; |
| 31 | +req.on('close',common.mustCall(()=>{})); |
41 | 32 |
|
| 33 | +req.on('connect',common.mustCall((res,socket,firstBodyChunk)=>{ |
42 | 34 | // Make sure this request got removed from the pool. |
43 | | -varname='localhost:'+server.address().port; |
| 35 | +constname='localhost:'+server.address().port; |
44 | 36 | assert(!http.globalAgent.sockets.hasOwnProperty(name)); |
45 | 37 | assert(!http.globalAgent.requests.hasOwnProperty(name)); |
46 | 38 |
|
47 | 39 | // Make sure this socket has detached. |
48 | 40 | assert(!socket.ondata); |
49 | 41 | assert(!socket.onend); |
50 | | -assert.equal(socket.listeners('connect').length,0); |
51 | | -assert.equal(socket.listeners('data').length,0); |
| 42 | +assert.strictEqual(socket.listeners('connect').length,0); |
| 43 | +assert.strictEqual(socket.listeners('data').length,0); |
52 | 44 |
|
53 | 45 | // the stream.Duplex onend listener |
54 | 46 | // allow 0 here, so that i can run the same test on streams1 impl |
55 | 47 | assert(socket.listeners('end').length<=1); |
56 | 48 |
|
57 | | -assert.equal(socket.listeners('free').length,0); |
58 | | -assert.equal(socket.listeners('close').length,0); |
59 | | -assert.equal(socket.listeners('error').length,0); |
60 | | -assert.equal(socket.listeners('agentRemove').length,0); |
| 49 | +assert.strictEqual(socket.listeners('free').length,0); |
| 50 | +assert.strictEqual(socket.listeners('close').length,0); |
| 51 | +assert.strictEqual(socket.listeners('error').length,0); |
| 52 | +assert.strictEqual(socket.listeners('agentRemove').length,0); |
61 | 53 |
|
62 | | -vardata=firstBodyChunk.toString(); |
63 | | -socket.on('data',function(buf){ |
| 54 | +letdata=firstBodyChunk.toString(); |
| 55 | +socket.on('data',(buf)=>{ |
64 | 56 | data+=buf.toString(); |
65 | 57 | }); |
66 | | -socket.on('end',function(){ |
67 | | -assert.equal(data,'HeadBody'); |
68 | | -assert(clientRequestClosed); |
| 58 | + |
| 59 | +socket.on('end',common.mustCall(()=>{ |
| 60 | +assert.strictEqual(data,'HeadBody'); |
69 | 61 | server.close(); |
70 | | -}); |
| 62 | +})); |
| 63 | + |
71 | 64 | socket.write('Body'); |
72 | 65 | socket.end(); |
73 | | -}); |
| 66 | +})); |
74 | 67 |
|
75 | 68 | // It is legal for the client to send some data intended for the server |
76 | 69 | // before the "200 Connection established" (or any other success or |
77 | 70 | // error code) is received. |
78 | 71 | req.write('Head'); |
79 | 72 | req.end(); |
80 | | -}); |
81 | | - |
82 | | -process.on('exit',function(){ |
83 | | -assert.ok(serverGotConnect); |
84 | | -assert.ok(clientGotConnect); |
85 | | -}); |
| 73 | +})); |
0 commit comments