Welcome to mirror list, hosted at ThFree Co, Russian Federation.

test-https-large-response.js « pummel « test - github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 36d78bbeb863ecd14fa46016b0eca14217076224 (plain)
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
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;

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;
    });
  });
});


process.on('exit', function () {
  assert.equal(1, reqCount);
  assert.equal(body.length, count);
  assert.ok(gotResEnd);
});