[英]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.