summaryrefslogtreecommitdiff
path: root/test/parallel/test-http-response-writehead-returns-this.js
blob: a62c2eca03585cd095d58716cd7e42b749ef5ed7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
'use strict';
require('../common');
const http = require('http');
const assert = require('assert');

const server = http.createServer((req, res) => {
  res.writeHead(200, { 'a-header': 'a-header-value' }).end('abc');
});

server.listen(0, () => {
  http.get({ port: server.address().port }, (res) => {
    assert.strictEqual(res.headers['a-header'], 'a-header-value');

    const chunks = [];

    res.on('data', (chunk) => chunks.push(chunk));
    res.on('end', () => {
      assert.strictEqual(Buffer.concat(chunks).toString(), 'abc');
      server.close();
    });
  });
});