aboutsummaryrefslogtreecommitdiff
path: root/test/parallel/test-http-write-empty-string.js
blob: 69463fb3a508526149bd0b83cf853d1c5ba3e7b0 (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
'use strict';
const common = require('../common');
const assert = require('assert');

const http = require('http');

const server = http.createServer(function(request, response) {
  console.log('responding to ' + request.url);

  response.writeHead(200, {'Content-Type': 'text/plain'});
  response.write('1\n');
  response.write('');
  response.write('2\n');
  response.write('');
  response.end('3\n');

  this.close();
});

server.listen(0, common.mustCall(function() {
  http.get({ port: this.address().port }, common.mustCall(function(res) {
    let response = '';

    assert.equal(200, res.statusCode);
    res.setEncoding('ascii');
    res.on('data', function(chunk) {
      response += chunk;
    });
    res.on('end', common.mustCall(function() {
      assert.strictEqual('1\n2\n3\n', response);
    }));
  }));
}));