forked from pbininda/node8keepAliveTimeout
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathclient.js
51 lines (44 loc) · 1.05 KB
/
client.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
const request = require('request');
const http = require('http');
const { readKeepAliveTimeout } = require("./utils");
const keepAliveTimeout = readKeepAliveTimeout();
let agent = new http.Agent({
keepAlive: true,
});
let baseUrl = 'http://localhost:9666';
function getStatus() {
request.get(baseUrl + '/status', {
agent: agent
}, (err, resp) => {
if (err) {
throw err;
}
console.log('Got get response', resp.statusCode, resp.body);
});
}
function run() {
request(baseUrl + '/longpost', {
method: 'OPTIONS',
agent: agent
}, (err, resp) => {
if (err) {
throw err;
}
console.log('Got options response', resp.statusCode);
console.log('Sending post request');
request.post(baseUrl + '/longpost', {
agent: agent,
json: true,
body: {id: 1},
headers: [
{ name: 'Connection', value: 'keep-alive' }
]
}, (err, resp) => {
if (err) {
throw err;
}
console.log('Got post response', resp.statusCode, resp.body);
});
});
}
setInterval(run, keepAliveTimeout);