-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxy.js
81 lines (76 loc) · 2.23 KB
/
proxy.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
const fs = require('fs')
const http = require('http')
const https = require('https')
const username = 'username'
const password = 'password'
const auth = 'Basic ' + Buffer.from(username + ':' + password).toString('base64')
var totalCount =0;
var maxCount = 10;
var totalTime = 0;
const host = "i.vimeocdn.com";
const hostPort = 443;
const hostPath = "/video/899768373.webp?mw=1400&mh=788";
const keepAliveAgent = new http.Agent({ keepAlive: true });
//options.agent = keepAliveAgent;
//http.request(options,callback);
function Timing() {
const timings = {
// use new Date() as it's not a subject of clock drift
startAt: new Date(),
dnsLookupAt: undefined,
tcpConnectionAt: undefined,
tlsHandshakeAt: undefined,
firstByteAt: undefined,
endAt: undefined
}
const req = https.request({
host: host, port: hostPort, path : hostPath
/*
host: "www.google.com",
port: 443,
method: 'get',
path: '/'
*/
//port: hostPort,
//path: hostPath
//agent: false
}, (res) => {
let chunks=[];
res.once('readable', () => {
timings.firstByteAt = new Date()
})
res.on('data', (chunk) => { chunks.push(chunk); })
res.on('end', () => {
timings.endAt = new Date()
var t= (timings.endAt - timings.startAt);
totalTime += t;
console.log("");
console.log("First Byte (ms): " + (timings.firstByteAt - timings.startAt));
console.log("DNS (ms) : " + (timings.dnsLookupAt - timings.startAt));
console.log("Connect (ms) : " + (timings.tcpConnectionAt - timings.startAt));
console.log("tls (ms) : " + (timings.tlsHandshakeAt - timings.startAt));
console.log("total time (ms): " + (timings.endAt - timings.startAt));
if (totalCount++ < maxCount) {
Timing();
}
else {
fs.writeFile('request.dat', Buffer.concat(chunks), 'utf8', function(err,data){});
console.log('last response was written to request.dat');
console.log("average time (ms): " + (totalTime/maxCount));
}
})
});
req.on('socket', (socket) => {
socket.on('lookup', () => {
timings.dnsLookupAt = new Date()
})
socket.on('connect', () => {
timings.tcpConnectionAt = new Date()
})
socket.on('secureConnect', () => {
timings.tlsHandshakeAt = new Date()
})
});
req.end();
}
Timing();