【发布时间】:2017-02-22 00:35:36
【问题描述】:
我编写了一个在 localhost:8000 上运行的小型代理服务器,它应该替换特定 url 上的一些内容,同时保持其他 url 不变。
它目前所做的是在example.com 页面上将Example Domain 替换为Hello World!。为了构建它,我使用了 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 url)时,它会失败,以ERR_EMPTY_RESPONSE结尾:
如何为我的代理服务器添加https 支持,或者至少让Chrome 绕过https url 到http?
我尝试使用 --ignore-certificate-errors 和 --allow-insecure-content 运行 Chrome 进程,但它们没有帮助。
我对拥有强大的 https 相关安全性并不感兴趣,但我想通过我的服务器代理这些 https 请求并在客户端上发送响应。
【问题讨论】:
标签: javascript html node.js google-chrome proxy