| 126 | } |
| 127 | |
| 128 | function onConnect(res, socket, header) { |
| 129 | assert.strictEqual(res.statusCode, 200); |
| 130 | console.log('CLIENT: got CONNECT response'); |
| 131 | |
| 132 | // detach the socket |
| 133 | socket.removeAllListeners('data'); |
| 134 | socket.removeAllListeners('close'); |
| 135 | socket.removeAllListeners('error'); |
| 136 | socket.removeAllListeners('drain'); |
| 137 | socket.removeAllListeners('end'); |
| 138 | socket.ondata = null; |
| 139 | socket.onend = null; |
| 140 | socket.ondrain = null; |
| 141 | |
| 142 | console.log('CLIENT: Making HTTPS request'); |
| 143 | |
| 144 | https.get({ |
| 145 | path: '/foo', |
| 146 | key: key, |
| 147 | cert: cert, |
| 148 | socket: socket, // reuse the socket |
| 149 | agent: false, |
| 150 | rejectUnauthorized: false |
| 151 | }, common.mustCall((res) => { |
| 152 | assert.strictEqual(res.statusCode, 200); |
| 153 | |
| 154 | res.on('data', common.mustCall((chunk) => { |
| 155 | assert.strictEqual(chunk.toString(), 'hello world\n'); |
| 156 | console.log('CLIENT: got HTTPS response'); |
| 157 | gotRequest = true; |
| 158 | })); |
| 159 | |
| 160 | res.on('end', common.mustCall(() => { |
| 161 | proxy.close(); |
| 162 | server.close(); |
| 163 | })); |
| 164 | })).on('error', (er) => { |
| 165 | // We're ok with getting ECONNRESET in this test, but it's |
| 166 | // timing-dependent, and thus unreliable. Any other errors |
| 167 | // are just failures, though. |
| 168 | if (er.code !== 'ECONNRESET') |
| 169 | throw er; |
| 170 | }).end(); |
| 171 | } |
| 172 | })); |
| 173 | |
| 174 | process.on('exit', () => { |