-
Notifications
You must be signed in to change notification settings - Fork 1
/
anyproxy.rule.js
42 lines (36 loc) · 1016 Bytes
/
anyproxy.rule.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'use strict';
const DISALLOWED_REQUEST_HEADERS = [
'host', 'proxy-connection',
].reduce((hash, v) => {
hash[v] = true;
return hash;
}, {});
if (!process.env.PROXYFRONT_HOST) {
throw new Error("`PROXYFRONT_HOST` was not found in environment variable.");
}
module.exports = {
*beforeSendRequest(requestDetail) {
const { requestOptions } = requestDetail;
const requestedUrl = requestDetail.url;
const safeHeaders = Object.keys(requestOptions.headers).reduce((hash, k) => {
if (!DISALLOWED_REQUEST_HEADERS[k.toLowerCase()]) {
hash[k] = requestOptions.headers[k];
}
return hash;
}, {});
requestOptions.hostname = process.env.PROXYFRONT_HOST;
requestOptions.port = 443;
requestOptions.path = `/${requestedUrl}`;
requestOptions.headers = {
...safeHeaders,
Host: process.env.PROXYFRONT_HOST,
};
return {
protocol: 'https',
requestOptions,
};
},
*beforeDealHttpsRequest(requestDetail) {
return true;
}
};