From df1bc9911aa1d0c1e67bd47cb7868b8ec76b0946 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8A=A0=E9=87=8C?= Date: Mon, 11 Aug 2014 17:48:32 +0800 Subject: [PATCH] fix http req over https --- .gitignore | 1 + bin.js | 1 + lib/requestHandler.js | 3 ++- package.json | 2 +- proxy.js | 3 ++- 5 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index d0b035a..6ed0009 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ .lock-wscript .svn .wafpickle-* +tmp.txt CVS npm-debug.log cert/**/*.srl diff --git a/bin.js b/bin.js index a334744..1fbf2c8 100644 --- a/bin.js +++ b/bin.js @@ -16,4 +16,5 @@ if(program.clear){ }else{ mainProxy.startServer(program.type,program.port, program.host); + } \ No newline at end of file diff --git a/lib/requestHandler.js b/lib/requestHandler.js index 2926980..c6c4e87 100644 --- a/lib/requestHandler.js +++ b/lib/requestHandler.js @@ -2,8 +2,9 @@ var http = require("http"), https = require("https"); function handler(req,userRes){ + console.log(req); - var ifHttps = !!req.connection.encrypted; + var ifHttps = !!req.connection.encrypted && !/http:/.test(req.url); var options = { hostname : req.headers.host, diff --git a/package.json b/package.json index fd29ecf..16ab03a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "anyproxy", - "version": "0.1.0", + "version": "0.1.1", "description": "https proxy over http", "main": "proxy.js", "bin": "bin.js", diff --git a/proxy.js b/proxy.js index e5c550b..e94a095 100644 --- a/proxy.js +++ b/proxy.js @@ -29,7 +29,7 @@ function startServer(type, port, hostname){ //creat server function(callback){ if(proxyType == T_TYPE_HTTPS){ - httpsServerMgr.getCertificate(proxyHost,function(err,keyContent,crtContent){ + certMgr.getCertificate(proxyHost,function(err,keyContent,crtContent){ if(err){ callback(err); }else{ @@ -44,6 +44,7 @@ function startServer(type, port, hostname){ }else{ httpProxyServer = http.createServer(requestHandler); callback(null); + } },