[英]How to support https in a local proxy server?
I've written a small proxy server running on localhost:8000
which is supposed to replace some content on specific urls, while leaving the other urls intact. 我编写了一个在
localhost:8000
上运行的小型代理服务器,该服务器应该替换特定URL上的某些内容,而其他URL保持原样。
What it currently does is to replace Example Domain
with Hello World!
当前所做的是用
Hello World!
替换Example Domain
Hello World!
on the example.com
page. 在
example.com
页面上。 To build this I used the proxy-tamper
package. 为此,我使用了
proxy-tamper
包。
The code looks like this (saved in proxy-server.js
): 代码如下(保存在
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();
});
});
Then, to start the proxy server I use: 然后,要启动代理服务器,请使用:
node proxy-server.js
And finally, start google-chrome-stable
, by setting the --proxy-server
option: 最后,通过设置
--proxy-server
选项启动google-chrome-stable
:
google-chrome-stable --proxy-server='http=http://localhost:8000;https=http://localhost:8000' http://domain.com
This works nicely for http://example.com
but fails for https://example.com
. 这对于
http://example.com
效果很好,但对于https://example.com
却效果不佳。 In fact it doesn't support https
. 实际上,它不支持
https
。
When I open http://example.com
I see the replaced content: 当我打开
http://example.com
我看到了替换的内容:
But when I open https://example.com
(or any https
url), it fails, ending with ERR_EMPTY_RESPONSE
: 但是,当我打开
https://example.com
(或任何https
网址)时,它失败,并以ERR_EMPTY_RESPONSE
结尾:
How can I add https
support for my proxy server, or at least make Chrome bypass the https
urls to http
? 如何添加对代理服务器的
https
支持,或至少使Chrome浏览器将https
网址绕过http
?
I tried running the Chrome process using --ignore-certificate-errors
and --allow-insecure-content
, but they didn't help. 我尝试使用
--ignore-certificate-errors
和--allow-insecure-content
运行Chrome进程,但它们没有帮助。
I'm not primary interested to have a strong https-related security, but I want to proxy these https requests through my server and send the responses on the client. 我对拥有与https相关的强大安全性并不感兴趣,但是我想通过我的服务器代理这些https请求并在客户端上发送响应。
It looks like proxy-tamper has no functionality for https requests. 似乎代理篡改不支持https请求。 It only supports http (as of writing this and looking at the documentation).
它仅支持http(在编写本文和查看文档时)。
You could use the package node-http-proxy instead. 您可以改用node-http-proxy软件包。 There's a nice section on supporting https here .
有一个关于支持HTTPS一个很好的部分在这里 。
Edit Can someone verify whether you can actually change https response bodies server side? 编辑有人可以验证您是否可以实际更改https响应正文服务器端吗? Won't this information technically be encrypted?
从技术上讲,此信息不会加密吗? Isn't decryption on the server technically breaching the protocol and not allowed?
服务器上的解密在技术上是否违反协议并且被禁止?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.