mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-04-23 15:31:26 +00:00
update git info in package.json
This commit is contained in:
parent
978b549be7
commit
a0fd07fbc8
@ -18,7 +18,7 @@ What this proxy do is to generate and replace a temporary cert for any domain if
|
|||||||
* generate and intercept https requests for any domain without complaint by browser (after you trust its root CA)
|
* generate and intercept https requests for any domain without complaint by browser (after you trust its root CA)
|
||||||
* can be used globally or as a nodejs module
|
* can be used globally or as a nodejs module
|
||||||
|
|
||||||
## How to use
|
## Usage
|
||||||
### step 0 - setup env
|
### step 0 - setup env
|
||||||
|
|
||||||
* install NodeJS
|
* install NodeJS
|
||||||
@ -56,7 +56,7 @@ npm install anyproxy
|
|||||||
var proxy = require("anyproxy");
|
var proxy = require("anyproxy");
|
||||||
|
|
||||||
!proxy.isRootCAFileExists() && proxy.generateRootCA();
|
!proxy.isRootCAFileExists() && proxy.generateRootCA();
|
||||||
proxy.startServer("http","8001", "localhost" ,"path/to/rule/file");
|
new proxy.proxyServer("http","8001", "localhost" ,"path/to/rule/file");
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
2
bin.js
2
bin.js
@ -25,5 +25,5 @@ if(program.clear){
|
|||||||
process.exit(0);
|
process.exit(0);
|
||||||
});
|
});
|
||||||
}else{
|
}else{
|
||||||
proxy.startServer(program.type,program.port, program.host ,program.rule);
|
new proxy.proxyServer(program.type,program.port, program.host ,program.rule);
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "anyproxy",
|
"name": "anyproxy",
|
||||||
"version": "1.1.0",
|
"version": "1.1.1",
|
||||||
"description": "a charles/fiddle like web proxy for developers which can intercept https requests without browser warning",
|
"description": "a charles/fiddle like web proxy for developers which can intercept https requests without browser warning",
|
||||||
"main": "proxy.js",
|
"main": "proxy.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
@ -14,7 +14,11 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {},
|
"devDependencies": {},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "nodeunit test.js"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/ottomao/anyproxy.git"
|
||||||
},
|
},
|
||||||
"author": "ottomao@gmail.com",
|
"author": "ottomao@gmail.com",
|
||||||
"license": "ISC"
|
"license": "ISC"
|
||||||
|
30
proxy.js
30
proxy.js
@ -1,3 +1,5 @@
|
|||||||
|
//TODO : get free port
|
||||||
|
|
||||||
var http = require('http'),
|
var http = require('http'),
|
||||||
https = require('https'),
|
https = require('https'),
|
||||||
fs = require('fs'),
|
fs = require('fs'),
|
||||||
@ -16,13 +18,15 @@ var T_TYPE_HTTP = 0,
|
|||||||
DEFAULT_HOST = "localhost",
|
DEFAULT_HOST = "localhost",
|
||||||
DEFAULT_TYPE = T_TYPE_HTTP;
|
DEFAULT_TYPE = T_TYPE_HTTP;
|
||||||
|
|
||||||
function startServer(type, port, hostname,ruleFile){
|
function proxyServer(type, port, hostname,ruleFile){
|
||||||
var proxyType = /https/i.test(type || DEFAULT_TYPE) ? T_TYPE_HTTPS : T_TYPE_HTTP ,
|
var self = this,
|
||||||
|
proxyType = /https/i.test(type || DEFAULT_TYPE) ? T_TYPE_HTTPS : T_TYPE_HTTP ,
|
||||||
proxyPort = port || DEFAULT_PORT,
|
proxyPort = port || DEFAULT_PORT,
|
||||||
proxyHost = hostname || DEFAULT_HOST,
|
proxyHost = hostname || DEFAULT_HOST;
|
||||||
httpProxyServer;
|
|
||||||
|
|
||||||
if(ruleFile){
|
self.httpProxyServer = null;
|
||||||
|
|
||||||
|
if(ruleFile){ //TODO : fs.join
|
||||||
if(fs.existsSync(ruleFile)){
|
if(fs.existsSync(ruleFile)){
|
||||||
requestHandler.setRules(require(ruleFile));
|
requestHandler.setRules(require(ruleFile));
|
||||||
console.log(color.green("rule file loaded"));
|
console.log(color.green("rule file loaded"));
|
||||||
@ -31,8 +35,8 @@ function startServer(type, port, hostname,ruleFile){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async.series([
|
async.series(
|
||||||
|
[
|
||||||
//creat proxy server
|
//creat proxy server
|
||||||
function(callback){
|
function(callback){
|
||||||
if(proxyType == T_TYPE_HTTPS){
|
if(proxyType == T_TYPE_HTTPS){
|
||||||
@ -40,7 +44,7 @@ function startServer(type, port, hostname,ruleFile){
|
|||||||
if(err){
|
if(err){
|
||||||
callback(err);
|
callback(err);
|
||||||
}else{
|
}else{
|
||||||
httpProxyServer = https.createServer({
|
self.httpProxyServer = https.createServer({
|
||||||
key : keyContent,
|
key : keyContent,
|
||||||
cert: crtContent
|
cert: crtContent
|
||||||
},requestHandler.userRequestHandler);
|
},requestHandler.userRequestHandler);
|
||||||
@ -49,15 +53,15 @@ function startServer(type, port, hostname,ruleFile){
|
|||||||
});
|
});
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
httpProxyServer = http.createServer(requestHandler.userRequestHandler);
|
self.httpProxyServer = http.createServer(requestHandler.userRequestHandler);
|
||||||
callback(null);
|
callback(null);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
//listen CONNECT method for https over http
|
//listen CONNECT method for https over http
|
||||||
function(callback){
|
function(callback){
|
||||||
httpProxyServer.on('connect',requestHandler.connectReqHandler);
|
self.httpProxyServer.on('connect',requestHandler.connectReqHandler);
|
||||||
httpProxyServer.listen(proxyPort);
|
self.httpProxyServer.listen(proxyPort);
|
||||||
callback(null);
|
callback(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,8 +79,10 @@ function startServer(type, port, hostname,ruleFile){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
return self.httpProxyServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.startServer = startServer;
|
module.exports.proxyServer = proxyServer;
|
||||||
module.exports.generateRootCA = certMgr.generateRootCA;
|
module.exports.generateRootCA = certMgr.generateRootCA;
|
||||||
module.exports.isRootCAFileExists = certMgr.isRootCAFileExists;
|
module.exports.isRootCAFileExists = certMgr.isRootCAFileExists;
|
22
test.js
22
test.js
@ -1,16 +1,20 @@
|
|||||||
var https = require("https");
|
|
||||||
|
var https = require("https"),
|
||||||
|
http = require("http");
|
||||||
|
|
||||||
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';
|
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
host: "localhost",
|
host: "localhost",
|
||||||
port: 8001,
|
port: 8001,
|
||||||
path: "/",
|
path: "/",
|
||||||
headers: {
|
headers: {
|
||||||
Host: "www.alipay.com"
|
Host: "www.alipay.com"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
https.get(options, function(res) {
|
https.get(options, function(res) {
|
||||||
console.log(res);
|
console.log(res);
|
||||||
res.pipe(process.stdout);
|
res.pipe(process.stdout);
|
||||||
});
|
});
|
Loading…
x
Reference in New Issue
Block a user