From 844c785d4b15a9ffcff0bde30a8badb5f51cd3c4 Mon Sep 17 00:00:00 2001 From: Xzandro Date: Mon, 13 Mar 2017 07:52:29 +0100 Subject: [PATCH] Fixed ERR_RESPONSE_EMPTY error with https sites and connections --- app/proxy/SWProxy.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/app/proxy/SWProxy.js b/app/proxy/SWProxy.js index 96889183..997a886c 100644 --- a/app/proxy/SWProxy.js +++ b/app/proxy/SWProxy.js @@ -2,6 +2,8 @@ const EventEmitter = require('events'); const http = require('http') const httpProxy = require('http-proxy'); const os = require('os'); +const net = require('net'); +const url = require('url'); const {decrypt_request, decrypt_response} = require('./smon_decryptor'); @@ -73,6 +75,23 @@ class SWProxy extends EventEmitter { this.proxy.web(req, resp, { target: req.url, prependPath: false }); }).listen(port); + + this.httpServer.on('connect', function (req, socket) { + let serverUrl = url.parse('https://' + req.url); + + let srvSocket = net.connect(serverUrl.port, serverUrl.hostname, function() { + socket.write('HTTP/1.1 200 Connection Established\r\n' + + 'Proxy-agent: Node-Proxy\r\n' + + '\r\n'); + srvSocket.pipe(socket); + socket.pipe(srvSocket); + }); + + srvSocket.on('error', (error) => { + console.log('Caught server socket error.'); + }); + }); + this.log({ type: 'info', source: 'proxy', message: `Now listening on port ${port}` }); }