* close the proxy server * * @returns ProxyCore * * @memberOf ProxyCore
()
| 257 | * @memberOf ProxyCore |
| 258 | */ |
| 259 | close() { |
| 260 | // clear recorder cache |
| 261 | return new Promise((resolve) => { |
| 262 | if (this.httpProxyServer) { |
| 263 | // destroy conns & cltSockets when closing proxy server |
| 264 | for (const connItem of this.requestHandler.conns) { |
| 265 | const key = connItem[0]; |
| 266 | const conn = connItem[1]; |
| 267 | logUtil.printLog(`destorying https connection : ${key}`); |
| 268 | conn.end(); |
| 269 | } |
| 270 | |
| 271 | for (const cltSocketItem of this.requestHandler.cltSockets) { |
| 272 | const key = cltSocketItem[0]; |
| 273 | const cltSocket = cltSocketItem[1]; |
| 274 | logUtil.printLog(`endding https cltSocket : ${key}`); |
| 275 | cltSocket.end(); |
| 276 | } |
| 277 | |
| 278 | if (this.socketPool) { |
| 279 | for (const key in this.socketPool) { |
| 280 | this.socketPool[key].destroy(); |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | this.httpProxyServer.close((error) => { |
| 285 | if (error) { |
| 286 | console.error(error); |
| 287 | logUtil.printLog(`proxy server close FAILED : ${error.message}`, logUtil.T_ERR); |
| 288 | } else { |
| 289 | this.httpProxyServer = null; |
| 290 | |
| 291 | this.status = PROXY_STATUS_CLOSED; |
| 292 | logUtil.printLog(`proxy server closed at ${this.proxyHostName}:${this.proxyPort}`); |
| 293 | } |
| 294 | resolve(error); |
| 295 | }); |
| 296 | } else { |
| 297 | resolve(); |
| 298 | } |
| 299 | }) |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | /** |
no outgoing calls