diff options
author | XadillaX <admin@xcoder.in> | 2017-06-10 14:09:35 -0400 |
---|---|---|
committer | Refael Ackermann <refack@gmail.com> | 2017-06-14 15:14:34 -0400 |
commit | c1c226719f269f013f000e8ad9194254e6d83f51 (patch) | |
tree | e387688418a02a3363f54ad3a38f9d73b6d50fef /test/parallel/test-https-argument-of-creating.js | |
parent | 2f34bf0f772c590f49b4b4b11ad81549d0f8b04a (diff) | |
download | node-new-c1c226719f269f013f000e8ad9194254e6d83f51.tar.gz |
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: https://github.com/nodejs/node/pull/13599
Fixes: https://github.com/nodejs/node/issues/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>
Diffstat (limited to 'test/parallel/test-https-argument-of-creating.js')
-rw-r--r-- | test/parallel/test-https-argument-of-creating.js | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/test/parallel/test-https-argument-of-creating.js b/test/parallel/test-https-argument-of-creating.js new file mode 100644 index 0000000000..87d934316f --- /dev/null +++ b/test/parallel/test-https-argument-of-creating.js @@ -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); +} |