summaryrefslogtreecommitdiff
path: root/test/parallel/test-https-server-options-server-response.js
blob: 8745415f8b659688893ead5f5b2299bbefb2b02f (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
36
37
38
39
40
41
42
43
44
45
46
47
'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 fixtures = require('../common/fixtures');

if (!common.hasCrypto)
  common.skip('missing crypto');

const assert = require('assert');
const http = require('http');
const https = require('https');

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

const server = https.createServer({
  key: fixtures.readKey('agent1-key.pem'),
  cert: fixtures.readKey('agent1-cert.pem'),
  ca: fixtures.readKey('ca1-cert.pem'),
  ServerResponse: MyServerResponse
}, common.mustCall(function(req, res) {
  res.status(200);
  res.end();
}));
server.listen();

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