小编use*_*478的帖子

node.js中的HTTPS代理服务器

我正在开发node.js代理服务器应用程序,我希望它支持HTTPHTTPS(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:

如果我订阅upgradehttpProxy服务器对象的事件,我可以获得请求,但我不知道如何转发请求并向客户端发送响应:

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)

任何帮助将不胜感激.

ssl https proxy http node.js

35
推荐指数
4
解决办法
4万
查看次数

标签 统计

http ×1

https ×1

node.js ×1

proxy ×1

ssl ×1