AnyProxy
AnyProxy is a fully configurable http/https proxy in NodeJS. Version 4.0 is in beta now.
Ref: Chinese Doc 中文文档
-Github:
+Github:
@@ -99,6 +101,8 @@Quick start
install
+To Debian and Ubuntu users, you may need to install nodejs-legacy
at the same time
sudo apg-get install nodejs-legacy
Then install the AnyProxy
npm install -g anyproxy@beta # 4.x is in beta now
launch
- start AnyProxy in command line, with default port 8001 @@ -172,11 +176,11 @@ anyproxy --intercept #launch anyproxy and intercept a
Step 3, test
-
-
use curl
+use curl
curl http://httpbin.org/user-agent --proxy http://127.0.0.1:8001
-use browser. Point the http proxy of browser to 127.0.0.1:8001, then visit http://httpbin.org/user-agent
+use browser. Point the http proxy of browser to 127.0.0.1:8001, then visit http://httpbin.org/user-agent
-the expected response from proxy is
+the expected response from proxy is
{ @@ -229,17 +233,17 @@ npm i -g myRulePkg && anyproxy --rule myRulePkg
module.exports = { // introduction - summary: 'my customized rule for AnyProxy', + summary: 'my customized rule for AnyProxy', // intercept before send request to server - *beforeSendRequest(requestDetail) { /* ... */ }, - // deal response before send to client - *beforeSendResponse(requestDetail, responseDetail) { /* ... */ }, + *beforeSendRequest(requestDetail) { /* ... */ }, + // deal response before send to client + *beforeSendResponse(requestDetail, responseDetail) { /* ... */ }, // if deal https request - *beforeDealHttpsRequest(requestDetail) { /* ... */ }, + *beforeDealHttpsRequest(requestDetail) { /* ... */ }, // error happened when dealing requests - *onError(requestDetail, error) { /* ... */ }, + *onError(requestDetail, error) { /* ... */ }, // error happened when connect to https server - *onConnectError(requestDetail, error) { /* ... */ } + *onConnectError(requestDetail, error) { /* ... */ } };
All functions in your rule file, except summary, are all driven by co . They should be yieldable, i.e. return a promise or be a generator function.
- Before sending request to server, AnyProxy will call
beforeSendRequest
with paramrequestDetail
- requestDetail
-
+
requestDetail
protocol
{string} the protocol to use, http or httpsrequestOptions
{object} the options of the request-to-go, a param of require('http').request . ref: https://nodejs.org/api/http.html#http_http_request_options_callbackrequestData
{object} request body
@@ -316,16 +320,16 @@ newOption.path = '/redirect/to/another/path';
- Before sending response to client, AnyProxy will call
beforeSendResponse
with paramrequestDetail
responseDetail
requestDetail
is the same param as inbeforeSendRequest
-responseDetail
-
+
responseDetail
response
{object} the response from server, includesstatusCode
header
body
_res
{object} the native node.js response object
e.g. When requesting anyproxy.io,
-responseDetail
is something like the following{ - response: { +
{ + response: { statusCode: 200, - header: { + header: { 'Content-Type': 'image/gif', Connection: 'close', 'Cache-Control': '...' @@ -396,12 +400,12 @@ newResponse.body += '--from anyproxy--';
- AnyProxy will call this method when failed to connect target server in https request
requestDetail
is the same one as inbeforeDealHttpsRequest
-- no return value is required +
- no return value is required
FAQ
- Q: can not deal https request in rule module. -
A: Any of these options could be used to change the way AnyProxy deall https requests
+A: Any of these options could be used to change the way AnyProxy deall https requests
- config
--intercept
when luanching AnyProxy via cli, or useforceProxyHttps
when using as an npm module - place a
beforeDealHttpsRequest
function in your rule file and determine which request to intercept by your own.
@@ -683,7 +687,7 @@ proxyServer.close();
- config
- sample
// set 127.0.0.1:8001 as system http server -AnyProxy.utils.systemProxyMgr.enableGlobalProxy('127.0.0.1', '8001'); +AnyProxy.utils.systemProxyMgr.enableGlobalProxy('127.0.0.1', '8001'); // disable global proxy server AnyProxy.utils.systemProxyMgr.disableGlobalProxy();
@@ -782,6 +786,36 @@ AnyProxy.utils.systemProxyMgr.disableGlobalProxy();
- Android
If you run AnyProxy by command line
+
Pass in the option--ignore-unauthorized-ssl
to ignore all the certificate errors.anyproxy -i --ignore-unauthorized-ssl
+If you run AnyProxy as an npm module
+
Pass in the optiondangerouslyIgnoreUnauthorized:true
, like this:const options = { + ..., + dangerouslyIgnoreUnauthorized: true +}; + +const anyproxyIns = new AnyProxy.ProxyCore(options); // it would apply to all requests +anyproxyIns.start();
+With the help of AnyProxy Rule
+By pass in
+rejectUnauthorized
, you could ignore SSL error in some specified request.module.exports = { + *beforeSendRequest(requestDetail) { + if (requestDetail.url.indexOf('https://the-site-you-know.com') === 0) { + const newRequestOptions = requestDetail.requestOptions; + // set rejectUnauthorized as false + newRequestOptions.rejectUnauthorized = false; + return { + requestOptions: newRequestOptions + }; + } + }, +};
+
+FAQ
+The connection is not private
+AnyProxy will propmt this message when the certificate of the site you're visiting is not issued by a trusted CA.(e.g. Node uses an hardcoded list of certificate authorities)
+You could ignore this kind of error at your own risk. The following is a how-to guide.
+-
+