11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ci/**
41cb0ef41Sopenharmony_ci * This test covers http.Server({ ServerResponse }) option:
51cb0ef41Sopenharmony_ci * With ServerResponse option the server should use
61cb0ef41Sopenharmony_ci * the new class for creating res Object instead of the default
71cb0ef41Sopenharmony_ci * http.ServerResponse.
81cb0ef41Sopenharmony_ci */
91cb0ef41Sopenharmony_ciconst common = require('../common');
101cb0ef41Sopenharmony_ciconst assert = require('assert');
111cb0ef41Sopenharmony_ciconst http = require('http');
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ciclass MyServerResponse extends http.ServerResponse {
141cb0ef41Sopenharmony_ci  status(code) {
151cb0ef41Sopenharmony_ci    return this.writeHead(code, { 'Content-Type': 'text/plain' });
161cb0ef41Sopenharmony_ci  }
171cb0ef41Sopenharmony_ci}
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ciconst server = http.Server({
201cb0ef41Sopenharmony_ci  ServerResponse: MyServerResponse
211cb0ef41Sopenharmony_ci}, common.mustCall(function(req, res) {
221cb0ef41Sopenharmony_ci  res.status(200);
231cb0ef41Sopenharmony_ci  res.end();
241cb0ef41Sopenharmony_ci}));
251cb0ef41Sopenharmony_ciserver.listen();
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_ciserver.on('listening', function makeRequest() {
281cb0ef41Sopenharmony_ci  http.get({ port: this.address().port }, (res) => {
291cb0ef41Sopenharmony_ci    assert.strictEqual(res.statusCode, 200);
301cb0ef41Sopenharmony_ci    res.on('end', () => {
311cb0ef41Sopenharmony_ci      server.close();
321cb0ef41Sopenharmony_ci    });
331cb0ef41Sopenharmony_ci    res.resume();
341cb0ef41Sopenharmony_ci  });
351cb0ef41Sopenharmony_ci});
36