繁体   English   中英

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

[英]How to support https in a local proxy server?

我编写了一个在localhost:8000上运行的小型代理服务器,该服务器应该替换特定URL上的某些内容,而其他URL保持原样。

当前所做的是用Hello World!替换Example Domain Hello World! example.com页面上。 为此,我使用了proxy-tamper包。

代码如下(保存在proxy-server.js ):

"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

最后,通过设置--proxy-server选项启动google-chrome-stable

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支持,或至少使Chrome浏览器将https网址绕过http

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

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

似乎代理篡改不支持https请求。 它仅支持http(在编写本文和查看文档时)。

您可以改用node-http-proxy软件包。 有一个关于支持HTTPS一个很好的部分在这里

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM