mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
http: add options to http.createServer()
This adds the optional options argument to `http.createServer()`. It contains two options: the `IncomingMessage` and `ServerReponse` option. Backport-PR-URL: https://github.com/nodejs/node/pull/20456 PR-URL: https://github.com/nodejs/node/pull/15752 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com>
This commit is contained in:
1 parent
0cae3c3fe5
commit
01dc646382
9 files changed
+222
-10
No files matched your search
@@ -0,0 +1,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();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user