From 8582a3cd77e8224ea351663aab996694a2e29527 Mon Sep 17 00:00:00 2001 From: OttoMao Date: Mon, 10 Nov 2014 15:08:50 +0800 Subject: [PATCH] move some module to optionalDep --- lib/requestHandler.js | 12 ++---------- package.json | 26 ++++++++++++++------------ proxy.js | 24 ++++++++++++++---------- 3 files changed, 30 insertions(+), 32 deletions(-) diff --git a/lib/requestHandler.js b/lib/requestHandler.js index 8b05baf..ea794d4 100644 --- a/lib/requestHandler.js +++ b/lib/requestHandler.js @@ -10,9 +10,7 @@ var http = require("http"), Buffer = require('buffer').Buffer, util = require("./util"), Stream = require("stream"), - httpsServerMgr = require("./httpsServerMgr"), - HttpProxyAgent = require("http-proxy-agent"), - HttpsProxyAgent= require("https-proxy-agent"); + httpsServerMgr = require("./httpsServerMgr"); var httpsServerMgrInstance = new httpsServerMgr(), defaultRule = require("./rule_default.js"), @@ -111,13 +109,7 @@ function userRequestHandler(req,userRes){ method : req.method, headers : req.headers }; - userRule.externalHttpProxies = userRule.externalHttpProxies || []; - if(userRule.externalHttpProxies.length){ - var agent = null, externalProxy = userRule.externalHttpProxies[Math.floor(Math.random()*userRule.externalHttpProxies.length)]; - agent = new HttpProxyAgent(externalProxy); - if(agent)options.agent = agent; - console.log(color.blue('this request is using ' + externalProxy + ' as external proxy')); - } + options = userRule.replaceRequestOption(req,options) || options; //update quest data diff --git a/package.json b/package.json index 4385b1c..dfa3c23 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "anyproxy", - "version": "2.8.1", + "version": "2.8.2", "description": "A fully configurable proxy in NodeJS, which can handle HTTPS requests perfectly.", "main": "proxy.js", "bin": { @@ -13,26 +13,28 @@ "commander": "~2.3.0", "entities": "^1.1.1", "express": "^4.8.5", - "iconv-lite": "^0.4.4", - "ip": "^0.3.2", - "jquery": "^2.1.1", - "jsdom": "^1.0.3", "juicer": "^0.6.6-stable", "nedb": "^0.11.0", "qrcode-npm": "0.0.3", - "socks5-http-client": "^0.1.6", - "socks5-https-client": "^0.2.2", "stream-throttle": "^0.1.3", - "ws": "^0.4.32", - "cookie":"^0.1.2", - "mysql":"^2.5.2", - "http-proxy-agent":"^0.2.6", - "https-proxy-agent":"^0.3.5" + "ws": "^0.4.32" }, "devDependencies": {}, "scripts": { "test": "nodeunit test.js" }, + "optionalDependencies":{ + "cookie":"^0.1.2", + "mysql":"^2.5.2", + "iconv-lite": "^0.4.4", + "ip": "^0.3.2", + "jquery": "^2.1.1", + "jsdom": "^1.0.3", + "socks5-http-client": "^0.1.6", + "socks5-https-client": "^0.2.2", + "http-proxy-agent":"^0.2.6", + "https-proxy-agent":"^0.3.5" + }, "repository": { "type":"git", "url" :"https://github.com/alibaba/anyproxy" diff --git a/proxy.js b/proxy.js index d130db7..1e7ae92 100644 --- a/proxy.js +++ b/proxy.js @@ -1,15 +1,19 @@ //mix some modules to global.util try{ - GLOBAL.util = require('./lib/util'); - GLOBAL.util['iconv-lite'] = require("iconv-lite"); - GLOBAL.util['colorful'] = require("colorful"); - GLOBAL.util['path'] = require("path"); - GLOBAL.util['jsdom'] = require('jsdom'); - GLOBAL.util['cookie'] = require('cookie'); - GLOBAL.util['jquery'] = require('jquery'); - GLOBAL.util['mysql'] = require('mysql'); - GLOBAL.util['Socks5ClientHttpAgent'] = require('socks5-http-client/lib/Agent'); - GLOBAL.util['Socks5ClientHttpsAgent'] = require('socks5-https-client/lib/Agent'); + GLOBAL.util = require('./lib/util'); + GLOBAL.util['iconv-lite'] = require("iconv-lite"); + GLOBAL.util['colorful'] = require("colorful"); + GLOBAL.util['path'] = require("path"); + GLOBAL.util['jsdom'] = require('jsdom'); + GLOBAL.util['cookie'] = require('cookie'); + GLOBAL.util['jquery'] = require('jquery'); + GLOBAL.util['mysql'] = require('mysql'); + GLOBAL.util['Socks5ClientHttpAgent'] = require('socks5-http-client/lib/Agent'); + GLOBAL.util['Socks5ClientHttpsAgent'] = require('socks5-https-client/lib/Agent'); + GLOBAL.util['HttpProxyAgent'] = require("http-proxy-agent"); + GLOBAL.util['HttpsProxyAgent'] = require("https-proxy-agent"); + + }catch(e){} var http = require('http'),