• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3/**
4 * This test covers http.Server({ ServerResponse }) option:
5 * With ServerResponse option the server should use
6 * the new class for creating res Object instead of the default
7 * http.ServerResponse.
8 */
9const common = require('../common');
10const fixtures = require('../common/fixtures');
11
12if (!common.hasCrypto)
13  common.skip('missing crypto');
14
15const assert = require('assert');
16const http = require('http');
17const https = require('https');
18
19class MyServerResponse extends http.ServerResponse {
20  status(code) {
21    return this.writeHead(code, { 'Content-Type': 'text/plain' });
22  }
23}
24
25const server = https.createServer({
26  key: fixtures.readKey('agent1-key.pem'),
27  cert: fixtures.readKey('agent1-cert.pem'),
28  ca: fixtures.readKey('ca1-cert.pem'),
29  ServerResponse: MyServerResponse
30}, common.mustCall(function(req, res) {
31  res.status(200);
32  res.end();
33}));
34server.listen();
35
36server.on('listening', function makeRequest() {
37  https.get({
38    port: this.address().port,
39    rejectUnauthorized: false
40  }, (res) => {
41    assert.strictEqual(res.statusCode, 200);
42    res.on('end', () => {
43      server.close();
44    });
45    res.resume();
46  });
47});
48