-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathhttps_agent.js
More file actions
47 lines (42 loc) Β· 1.16 KB
/
https_agent.js
File metadata and controls
47 lines (42 loc) Β· 1.16 KB
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
45
46
47
'use strict';
const https = require('https');
const HttpsAgent = require('..').HttpsAgent;
const agent = new HttpsAgent();
// https://www.google.com/search?q=nodejs&sugexp=chrome,mod=12&sourceid=chrome&ie=UTF-8
const options = {
host: 'github.com',
port: 443,
path: '/',
method: 'GET',
agent,
};
let start = Date.now();
const req = https.request(options, res => {
console.log('STATUS1: %d, %d ms', res.statusCode, Date.now() - start);
console.log('HEADERS1: %j', res.headers);
res.setEncoding('utf8');
res.on('data', chunk => {
console.log('BODY1: %d', chunk.length);
});
res.on('end', () => {
process.nextTick(() => {
start = Date.now();
https.get(options, res => {
console.log('STATUS2: %d, %d ms', res.statusCode, Date.now() - start);
console.log('HEADERS2: %j', res.headers);
res.setEncoding('utf8');
res.on('data', chunk => {
console.log('BODY2: %d', chunk.length);
});
});
});
});
});
req.on('error', e => {
console.log('problem with request: ' + e.message);
});
req.end();
setTimeout(() => {
console.log('keep alive sockets:', agent);
process.exit();
}, 5000);