• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2require('../common');
3const assert = require('assert');
4const http = require('http');
5const debug = require('util').debuglog('test');
6
7const testResBody = 'other stuff!\n';
8const kMessageCount = 2;
9
10const server = http.createServer((req, res) => {
11  for (let i = 0; i < kMessageCount; i++) {
12    debug(`Server sending informational message #${i}...`);
13    res.writeProcessing();
14  }
15  debug('Server sending full response...');
16  res.writeHead(200, {
17    'Content-Type': 'text/plain',
18    'ABCD': '1'
19  });
20  res.end(testResBody);
21});
22
23server.listen(0, function() {
24  const req = http.request({
25    port: this.address().port,
26    path: '/world'
27  });
28  req.end();
29  debug('Client sending request...');
30
31  let body = '';
32  let infoCount = 0;
33
34  req.on('information', () => { infoCount++; });
35
36  req.on('response', function(res) {
37    // Check that all 102 Processing received before full response received.
38    assert.strictEqual(infoCount, kMessageCount);
39    assert.strictEqual(res.statusCode, 200,
40                       `Final status code was ${res.statusCode}, not 200.`);
41    res.setEncoding('utf8');
42    res.on('data', function(chunk) { body += chunk; });
43    res.on('end', function() {
44      debug('Got full response.');
45      assert.strictEqual(body, testResBody);
46      assert.ok('abcd' in res.headers);
47      server.close();
48    });
49  });
50});
51