mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-08-04 21:39:04 +00:00
using SNI when intercepting https requests
This commit is contained in:
@@ -9,11 +9,11 @@ var http = require("http"),
|
||||
color = require("colorful"),
|
||||
Buffer = require('buffer').Buffer,
|
||||
util = require("./util"),
|
||||
getPort = require("./getPort"),
|
||||
Stream = require("stream"),
|
||||
httpsServerMgr = require("./httpsServerMgr");
|
||||
|
||||
var httpsServerMgrInstance = new httpsServerMgr(),
|
||||
defaultRule = require("./rule_default.js"),
|
||||
var defaultRule = require("./rule_default.js"),
|
||||
userRule = defaultRule; //init
|
||||
|
||||
function userRequestHandler(req,userRes){
|
||||
@@ -270,26 +270,40 @@ function connectReqHandler(req, socket, head){
|
||||
};
|
||||
resourceInfoId = GLOBAL.recorder.appendRecord(resourceInfo);
|
||||
|
||||
var proxyPort, proxyHost;
|
||||
var proxyPort,
|
||||
proxyHost,
|
||||
internalHttpsPort,
|
||||
httpsServerMgrInstance;
|
||||
|
||||
|
||||
async.series([
|
||||
|
||||
//find port
|
||||
//check if internal https server exists
|
||||
function(callback){
|
||||
if(internalHttpsPort){
|
||||
callback();
|
||||
}else{
|
||||
getPort(function(port){
|
||||
internalHttpsPort = port;
|
||||
httpsServerMgrInstance = new httpsServerMgr({
|
||||
port :port,
|
||||
handler :userRequestHandler
|
||||
});
|
||||
callback();
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
//determine the target server
|
||||
function(callback){
|
||||
|
||||
if(shouldIntercept){
|
||||
//TODO : remote port other than 433
|
||||
httpsServerMgrInstance.fetchPort(host,userRequestHandler,function(err,port){
|
||||
if(!err && port){
|
||||
proxyPort = port;
|
||||
proxyHost = "127.0.0.1";
|
||||
callback();
|
||||
}else{
|
||||
callback(err);
|
||||
}
|
||||
});
|
||||
proxyPort = internalHttpsPort;
|
||||
proxyHost = "127.0.0.1";
|
||||
callback();
|
||||
|
||||
}else{
|
||||
proxyPort = targetPort;
|
||||
proxyPort = 443;
|
||||
proxyHost = host;
|
||||
|
||||
callback();
|
||||
@@ -305,7 +319,6 @@ function connectReqHandler(req, socket, head){
|
||||
if(GLOBAL._throttle && !shouldIntercept ){
|
||||
var readable = conn.pipe(GLOBAL._throttle.throttle());
|
||||
readable.pipe(socket);
|
||||
|
||||
socket.pipe(conn);
|
||||
}else{
|
||||
conn.pipe(socket);
|
||||
|
||||
Reference in New Issue
Block a user