我正在使用 nodejs 创建一个简单的代理服务器来记录 http 和 https 请求,但是,我似乎无法记录 https 请求(http 请求很好)
那么如何在nodejs中创建一个可以设置安全连接的代理服务器呢?
到目前为止我的代码看起来像
var http = require('http'),
httpProxy = require('http-proxy'),
util = require('util'),
url = require('url');
httpProxy.createServer(function (request, response, proxy) {
util.log(request.connection.remoteAddress + ": " +
request.method + " " +
request.url);
request.addListener('data', function(chunk) {
util.log("request: " + chunk);
});
uri = url.parse(request.url);
port = 80;
if (uri.protocol == 'https:') { // NEVER HAPPENS :(
port = 443;
}
util.log("port:" + port + " host:" + uri.host);
proxy.proxyRequest(port, uri.hostname);
}).listen(8080);
它目前正在使用https://github.com/nodejitsu/node-http-proxy代理库,但是如果该库不支持 https(看起来不像是 atm,因为它在源代码中没有设置任何凭据......),我很高兴在没有它的情况下重写代理服务器。