-
Notifications
You must be signed in to change notification settings - Fork 3
/
inject-by-pass-server.js
30 lines (27 loc) · 1.04 KB
/
inject-by-pass-server.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
'use strict';
/*eslint require-yield: off*/
const HttpsProxyAgent = require('https-proxy-agent');
module.exports = externalProxy => {
return {
summary: 'Redirects to proxy server',
*beforeSendRequest(requestDetail) {
if (!externalProxy) {
return requestDetail;
}
if (requestDetail.protocol == 'https') {
const agent = new HttpsProxyAgent(externalProxy);
const newRequestOptions = requestDetail.requestOptions;
newRequestOptions.agent = agent;
return requestDetail;
}
if (requestDetail.protocol == 'http') {
const [address, port] = externalProxy && externalProxy.split(':') || [];
const newRequestOptions = requestDetail.requestOptions;
newRequestOptions.path = requestDetail.url;
newRequestOptions.hostname = address;
newRequestOptions.port = port;
return requestDetail;
}
}
};
};