summaryrefslogtreecommitdiff
path: root/test/parallel/test-http-flush-response-headers.js
blob: 0f0a1387b5673396c97198074867a0b2cc32cf22 (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
'use strict';
const common = require('../common');
const assert = require('assert');
const http = require('http');

const server = http.createServer();

server.on('request', function(req, res) {
  res.writeHead(200, { 'foo': 'bar' });
  res.flushHeaders();
  res.flushHeaders(); // Should be idempotent.
});
server.listen(0, common.localhostIPv4, function() {
  const req = http.request({
    method: 'GET',
    host: common.localhostIPv4,
    port: this.address().port,
  }, onResponse);

  req.end();

  function onResponse(res) {
    assert.strictEqual(res.headers.foo, 'bar');
    res.destroy();
    server.close();
  }
});