summaryrefslogtreecommitdiff
path: root/test/parallel/test-http-server-options-server-response.js
blob: f5adf39bed6d16e00edcac6a8b14e11a97c5685d (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
'use strict';

/**
 * This test covers http.Server({ ServerResponse }) option:
 * With ServerResponse option the server should use
 * the new class for creating res Object instead of the default
 * http.ServerResponse.
 */
const common = require('../common');
const assert = require('assert');
const http = require('http');

class MyServerResponse extends http.ServerResponse {
  status(code) {
    return this.writeHead(code, { 'Content-Type': 'text/plain' });
  }
}

const server = http.Server({
  ServerResponse: MyServerResponse
}, common.mustCall(function(req, res) {
  res.status(200);
  res.end();
}));
server.listen();

server.on('listening', function makeRequest() {
  http.get({ port: this.address().port }, (res) => {
    assert.strictEqual(res.statusCode, 200);
    res.on('end', () => {
      server.close();
    });
    res.resume();
  });
});