-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathalpn-negotiation.js
44 lines (36 loc) · 970 Bytes
/
alpn-negotiation.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
43
44
const http2wrapper = require('../../source/index.js');
const tls = require('tls');
(async () => {
const agentOptions = {
proxyOptions: {
url: new URL('https://username:password@localhost:8000'),
rejectUnauthorized: false
}
};
const destination = new URL('https://httpbin.org/anything');
const host = `${destination.host}:${destination.port || 443}`;
const request = await http2wrapper.auto(agentOptions.proxyOptions.url, {
rejectUnauthorized: agentOptions.proxyOptions.rejectUnauthorized,
method: 'CONNECT',
headers: {
host
},
path: host
});
request.end();
request.once('connect', (response, socket, head) => {
if (head.length > 0) {
// Handle unexpected data
return;
}
const tlsSocket = tls.connect({
socket,
servername: destination.hostname,
ALPNProtocols: ['h2', 'http/1.1']
});
tlsSocket.once('secure', () => {
console.log('handshake done');
console.log(tlsSocket.alpnProtocol);
});
});
})();