我正在开发node.js代理服务器应用程序,我希望它支持HTTP和HTTPS(SSL)协议(作为服务器).
我目前正在使用node-http-proxy这样的:
const httpProxy = require('http-proxy'),
http = require('http');
var server = httpProxy.createServer(9000, 'localhost', function(req, res, proxy) {
console.log(req.url);
proxy.proxyRequest(req, res);
});
http.createServer(function(req, res) {
res.end('hello!');
}).listen(9000);
server.listen(8000);
Run Code Online (Sandbox Code Playgroud)
我设置我的浏览器使用HTTP代理localhost:8000,它的工作原理.我还想捕获HTTPS请求(即设置我的浏览器以localhost:8000用作HTTPS代理并在我的应用程序中捕获请求).你能帮帮我怎么办?
PS:
如果我订阅upgrade了httpProxy服务器对象的事件,我可以获得请求,但我不知道如何转发请求并向客户端发送响应:
server.on('upgrade', function(req, socket, head) {
console.log(req.url);
// I don't know how to forward the request and send the response to client
});
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激.