2

我正在使用 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,因为它在源代码中没有设置任何凭据......),我很高兴在没有它的情况下重写代理服务器。

4

1 回答 1

0

看起来我暂时无法做到这一点,但有关于新 tls 模块的文档最终将使 https 连接正常工作。https://github.com/ry/node/blob/5a87bd168d8fbeca7d48b9ddaa3b4e8a9336719c/doc/api/tls.markdown

于 2010-12-09T07:13:52.980 回答