-
Notifications
You must be signed in to change notification settings - Fork 18
/
h2-over-h1.js
38 lines (32 loc) · 800 Bytes
/
h2-over-h1.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
'use strict';
const http2 = require('../../source/index.js'); // Note: using the local version
const agent = new http2.proxies.Http2OverHttps({
proxyOptions: {
url: 'https://username:password@localhost:8000',
// For demo purposes only!
rejectUnauthorized: false
}
});
const request = http2.request({
hostname: 'httpbin.org',
protocol: 'https:',
path: '/anything',
method: 'POST',
headers: {
'content-length': 6
},
agent
}, response => {
console.log('statusCode:', response.statusCode);
console.log('headers:', response.headers);
const body = [];
response.on('data', chunk => {
body.push(chunk);
});
response.on('end', () => {
console.log('body:', Buffer.concat(body).toString());
});
});
request.on('error', console.error);
request.write('123');
request.end('456');