如何在本地代理服务器中支持https?

时间:2016-10-13 03:05:58

标签: javascript html node.js google-chrome proxy

我写了一个在Example Domain上运行的小型代理服务器,它应该替换特定网址上的某些内容,同时保留其他网址不变。

目前的做法是将Hello World!替换为example.com页面上的proxy-server.js。为了构建这个,我使用了proxy-tamper包。

代码如下(保存在"use strict"; const proxy = require('proxy-tamper').start({port: 8000}); // block share-term.me proxy.tamper(/share-term.me\/$/, 'This content is blocked!'); // Replace the content on example.com proxy.tamper(/example.com\/$/, request => { delete request.headers['accept-encoding']; request.onResponse(response => { response.body = response.body.replace(/Example Domain/g, 'Hello World!'); response.headers['server'] = 'proxy-tamper 1337'; response.headers['content-length'] = response.body.length; response.complete(); }); }); 中):

node proxy-server.js

然后,为了启动我使用的代理服务器:

google-chrome-stable

最后,通过设置--proxy-server选项启动google-chrome-stable --proxy-server='http=http://localhost:8000;https=http://localhost:8000' http://domain.com

http://example.com

这适用于https://example.com,但https失败。实际上它不支持http://example.com

当我打开https://example.com时,我会看到替换的内容:

  

但是当我打开https(或任何ERR_EMPTY_RESPONSE网址)时,它会失败,以https结尾:

  

如何为我的代理服务器添加https支持,或至少让Chrome绕过http的{​​{1}}网址?

我尝试使用--ignore-certificate-errors--allow-insecure-content运行Chrome进程,但他们没有帮助。

我不是主要想要拥有强大的https相关安全性,但我想通过我的服务器代理这些https请求并在客户端上发送响应。

1 个答案:

答案 0 :(得分:0)

看起来代理篡改没有https请求的功能。它只支持http(编写本文并查看文档时)。

您可以使用包node-http-proxy代替。有一个很好的部分支持https here

编辑有人可以验证您是否可以实际更改https响应正文服务器端?这些信息在技术上不会被加密吗?服务器上的解密是否在技术上违反了协议并且不被允许?

相关问题