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.
What it currently does is to replace Example Domain
with Hello World!
on the example.com
page. To build this I used the proxy-tamper
package.
The code looks like this (saved in 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:
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
. In fact it doesn't support https
.
When I open http://example.com
I see the replaced content:
But when I open https://example.com
(or any https
url), it fails, ending with ERR_EMPTY_RESPONSE
:
How can I add https
support for my proxy server, or at least make Chrome bypass the https
urls to http
?
I tried running the Chrome process using --ignore-certificate-errors
and --allow-insecure-content
, but they didn't help.
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.
It looks like proxy-tamper has no functionality for https requests. It only supports http (as of writing this and looking at the documentation).
You could use the package node-http-proxy instead. There's a nice section on supporting https here .
Edit Can someone verify whether you can actually change https response bodies server side? Won't this information technically be encrypted? Isn't decryption on the server technically breaching the protocol and not allowed?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.