-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.js
65 lines (63 loc) · 1.57 KB
/
example.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const https = require("https");
const { DnsPolling, HttpsAgent } = require(".");
const pollingManager = new DnsPolling();
const agent = new HttpsAgent();
function makeRequest(hostname) {
const req = https.get(
{
hostname,
path: "/",
lookup: pollingManager.getLookup(hostname),
agent
},
res => {
const chunks = [];
res.on("data", chunk => {
chunks.push(chunk);
});
res.on("end", () => {
const body = Buffer.concat(chunks).toString("utf8");
console.log(
hostname,
req.socket.remoteAddress,
res.statusCode,
res.headers.date,
body.length
);
});
res.on("error", err => {
console.error("res error", err);
});
}
);
req.on("error", err => {
console.error("req error", err);
});
}
makeRequest("shuheikagawa.com");
makeRequest("github.com");
makeRequest("github.com");
setTimeout(() => {
makeRequest("shuheikagawa.com");
makeRequest("shuheikagawa.com");
makeRequest("shuheikagawa.com");
makeRequest("github.com");
makeRequest("github.com");
makeRequest("github.com");
}, 1000);
setTimeout(() => {
makeRequest("shuheikagawa.com");
makeRequest("shuheikagawa.com");
makeRequest("shuheikagawa.com");
makeRequest("github.com");
makeRequest("github.com");
makeRequest("github.com");
}, 2000);
setTimeout(() => {
makeRequest("shuheikagawa.com");
makeRequest("shuheikagawa.com");
makeRequest("shuheikagawa.com");
makeRequest("github.com");
makeRequest("github.com");
makeRequest("github.com");
}, 3000);