-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
https: make opts optional & immutable when create
`opts` in `createServer` will be immutable that won't change origional opts value. What's more, it's optional which can make `requestListener` be the first argument. PR-URL: #13599 Fixes: #13584 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Yorkie Liu <yorkiefixer@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
- Loading branch information
Showing
3 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
if (!common.hasCrypto) { | ||
common.skip('missing crypto'); | ||
return; | ||
} | ||
|
||
const assert = require('assert'); | ||
const https = require('https'); | ||
const tls = require('tls'); | ||
|
||
const dftProtocol = {}; | ||
|
||
// test for immutable `opts` | ||
{ | ||
const opts = { foo: 'bar', NPNProtocols: [ 'http/1.1' ] }; | ||
const server = https.createServer(opts); | ||
|
||
tls.convertNPNProtocols([ 'http/1.1' ], dftProtocol); | ||
assert.deepStrictEqual(opts, { foo: 'bar', NPNProtocols: [ 'http/1.1' ] }); | ||
assert.strictEqual(server.NPNProtocols.compare(dftProtocol.NPNProtocols), 0); | ||
} | ||
|
||
|
||
// validate that `createServer` can work with the only argument requestListener | ||
{ | ||
const mustNotCall = common.mustNotCall(); | ||
const server = https.createServer(mustNotCall); | ||
|
||
tls.convertNPNProtocols([ 'http/1.1', 'http/1.0' ], dftProtocol); | ||
assert.strictEqual(server.NPNProtocols.compare(dftProtocol.NPNProtocols), 0); | ||
assert.strictEqual(server.listeners('request').length, 1); | ||
assert.strictEqual(server.listeners('request')[0], mustNotCall); | ||
} | ||
|
||
|
||
// validate that `createServer` can work with no arguments | ||
{ | ||
const server = https.createServer(); | ||
|
||
assert.strictEqual(server.NPNProtocols.compare(dftProtocol.NPNProtocols), 0); | ||
assert.strictEqual(server.listeners('request').length, 0); | ||
} |