update git info in package.json

This commit is contained in:
加里 2014-08-14 22:58:30 +08:00
parent 978b549be7
commit a0fd07fbc8
5 changed files with 40 additions and 26 deletions

View File

@ -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)
* can be used globally or as a nodejs module
## How to use
## Usage
### step 0 - setup env
* install NodeJS
@ -56,7 +56,7 @@ npm install anyproxy
var proxy = require("anyproxy");
!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
View File

@ -25,5 +25,5 @@ if(program.clear){
process.exit(0);
});
}else{
proxy.startServer(program.type,program.port, program.host ,program.rule);
new proxy.proxyServer(program.type,program.port, program.host ,program.rule);
}

View File

@ -1,6 +1,6 @@
{
"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",
"main": "proxy.js",
"bin": {
@ -14,7 +14,11 @@
},
"devDependencies": {},
"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",
"license": "ISC"

View File

@ -1,3 +1,5 @@
//TODO : get free port
var http = require('http'),
https = require('https'),
fs = require('fs'),
@ -16,13 +18,15 @@ var T_TYPE_HTTP = 0,
DEFAULT_HOST = "localhost",
DEFAULT_TYPE = T_TYPE_HTTP;
function startServer(type, port, hostname,ruleFile){
var proxyType = /https/i.test(type || DEFAULT_TYPE) ? T_TYPE_HTTPS : T_TYPE_HTTP ,
function proxyServer(type, port, hostname,ruleFile){
var self = this,
proxyType = /https/i.test(type || DEFAULT_TYPE) ? T_TYPE_HTTPS : T_TYPE_HTTP ,
proxyPort = port || DEFAULT_PORT,
proxyHost = hostname || DEFAULT_HOST,
httpProxyServer;
proxyHost = hostname || DEFAULT_HOST;
if(ruleFile){
self.httpProxyServer = null;
if(ruleFile){ //TODO : fs.join
if(fs.existsSync(ruleFile)){
requestHandler.setRules(require(ruleFile));
console.log(color.green("rule file loaded"));
@ -31,8 +35,8 @@ function startServer(type, port, hostname,ruleFile){
}
}
async.series([
async.series(
[
//creat proxy server
function(callback){
if(proxyType == T_TYPE_HTTPS){
@ -40,7 +44,7 @@ function startServer(type, port, hostname,ruleFile){
if(err){
callback(err);
}else{
httpProxyServer = https.createServer({
self.httpProxyServer = https.createServer({
key : keyContent,
cert: crtContent
},requestHandler.userRequestHandler);
@ -49,15 +53,15 @@ function startServer(type, port, hostname,ruleFile){
});
}else{
httpProxyServer = http.createServer(requestHandler.userRequestHandler);
self.httpProxyServer = http.createServer(requestHandler.userRequestHandler);
callback(null);
}
},
//listen CONNECT method for https over http
function(callback){
httpProxyServer.on('connect',requestHandler.connectReqHandler);
httpProxyServer.listen(proxyPort);
self.httpProxyServer.on('connect',requestHandler.connectReqHandler);
self.httpProxyServer.listen(proxyPort);
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.isRootCAFileExists = certMgr.isRootCAFileExists;

View File

@ -1,7 +1,11 @@
var https = require("https");
var https = require("https"),
http = require("http");
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';
var options = {
host: "localhost",
port: 8001,