forked from nodejs/node-v0.x-archive
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-https-large-response.js
More file actions
66 lines (52 loc) · 1.4 KB
/
test-https-large-response.js
File metadata and controls
66 lines (52 loc) · 1.4 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
var common = require('../common');
var assert = require('assert');
var fs = require('fs');
var https = require('https');
var options = {
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')
};
var reqCount = 0;
var body = '';
process.stdout.write('build body...');
for (var i = 0; i < 1024*1024; i++) {
body += 'hello world\n';
}
process.stdout.write('done\n');
var server = https.createServer(options, function (req, res) {
reqCount++;
console.log('got request');
res.writeHead(200, { 'content-type': 'text/plain' });
res.end(body);
});
var count = 0;
var gotResEnd = false;
var timeout = setTimeout(function() {
process.exit(1);
}, 10*1000);
server.listen(common.PORT, function () {
https.get({ port: common.PORT }, function(res) {
console.log("response!");
res.on('data', function(d) {
process.stdout.write('.');
count += d.length;
res.pause();
process.nextTick(function () {
res.resume();
});
});
res.on('end', function(d) {
process.stdout.write('\n');
console.log("expected: ", body.length);
console.log(" got: ", count);
server.close();
gotResEnd = true;
clearTimeout(timeout);
});
});
});
process.on('exit', function () {
assert.equal(1, reqCount);
assert.equal(body.length, count);
assert.ok(gotResEnd);
});