forked from node-apn/node-apn
-
-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathproxy.js
More file actions
24 lines (22 loc) · 677 Bytes
/
proxy.js
File metadata and controls
24 lines (22 loc) · 677 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const http = require('http');
module.exports = function createProxySocket(proxy, target) {
return new Promise((resolve, reject) => {
let headers = { Connection: "Keep-Alive" };
if (proxy.user && proxy.pass) {
const token = Buffer.from(`${proxy.user}:${proxy.pass}`).toString('base64')
headers["Proxy-Authorization"] = `Basic ${token}`
}
const req = http.request({
host: proxy.host,
port: proxy.port,
method: "connect",
path: target.host + ":" + target.port,
headers: headers,
});
req.on('error', reject);
req.on('connect', (res, socket, head) => {
resolve(socket);
});
req.end();
});
};