Skip to content

Commit

Permalink
refactor: refine code
Browse files Browse the repository at this point in the history
  • Loading branch information
avwo committed Dec 2, 2020
1 parent 1ddbc07 commit ab7905f
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions lib/tunnel.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,31 +422,32 @@ function tunnelProxy(server, proxy) {
reqSocket.clientPort = req.clientPort;
reqSocket.globalValue = req.globalValue;
resSocket.statusCode = resData.statusCode;
if (buf) {
var _pipe = reqSocket.pipe;
reqSocket.pipe = function(stream) {
if (buf) {
stream.write(buf);
buf = null;
}
return _pipe.apply(this, arguments);
};
}
pluginMgr.resolvePipePlugin(reqSocket, function() {
data.pipe = reqSocket._pipeRule;
if (reqSocket._pipePluginPorts) {
reqSocket.inspectFrames = data.inspect = true;
reqSocket.customParser = false;
}
var connHandler = function() {
if (buf) {
var _pipe = reqSocket.pipe;
reqSocket.pipe = function(stream) {
if (buf) {
stream.write(buf);
buf = null;
}
return _pipe.apply(this, arguments);
};
}
socketMgr.handleConnect(reqSocket, resSocket);
};
var handleEstablished = function() {
if (useTunnelPolicy) {
sendEstablished(200, function() {
setTimeout(function() {
socketMgr.handleConnect(reqSocket, resSocket);
}, 16);
setTimeout(connHandler, 16);
});
} else {
socketMgr.handleConnect(reqSocket, resSocket);
connHandler();
sendEstablished();
}
};
Expand Down

0 comments on commit ab7905f

Please sign in to comment.