feat: auto reduce to http request

This commit is contained in:
avwo
2018-06-30 07:50:30 +08:00
parent dd921588e5
commit 91cbe499cb
3 changed files with 18 additions and 5 deletions
+11 -2
View File
@@ -304,7 +304,7 @@ function _handleWebsocket(socket, clientIp, clientPort, callback, wss) {
}
}
function connectServer(hostIp, hostPort) {
function connectServer(hostIp, hostPort, err) {
getServerIp(fullUrl, function(ip, port) {
var isWss = options.protocol === 'wss:';
socket.hostIp = resData.ip = port ? ip + ':' + port : ip;
@@ -316,7 +316,16 @@ function _handleWebsocket(socket, clientIp, clientPort, callback, wss) {
port: port,
servername: options.hostname
}, pipeData);
abortIfUnavailable(reqSocket);
if (err) {
abortIfUnavailable(reqSocket);
} else {
reqSocket.on('error', function(e) {
if (util.checkTlsHandUp(socket, ip, e)) {
options.protocol = null;
}
connectServer(hostIp, hostPort, e);
});
}
}, hostIp, hostPort);
}