Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34.4k
https: make opts optional & immutable when create#13599
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
26d4efb2c7ff7bb3a1ac69414765c798af85de8cf2dc2291c2232fadFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -34,6 +34,12 @@ const{urlToOptions, searchParamsSymbol } = require('internal/url'); | ||
| function Server(opts, requestListener){ | ||
| if (!(this instanceof Server)) return new Server(opts, requestListener); | ||
| if (typeof opts === 'function'){ | ||
| requestListener = opts; | ||
| opts = undefined; | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor nit: The optional value is an object, but here reset to ContributorAuthor
| ||
| } | ||
| opts = util._extend({}, opts); | ||
| if (process.features.tls_npn && !opts.NPNProtocols){ | ||
| opts.NPNProtocols = ['http/1.1', 'http/1.0']; | ||
| } | ||
| 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); | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we have to change this in the documentation, sinceHuh... I take that back, it doesn't seem to enforce a minimum configuration...tls.Server()will still require a configuration (a certificate and key at minimum). The benefit of guarding early beforetls.Server()is called is to avoid strange JavaScript runtime errors.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But a test in either way should be added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@refack the test is in test/parallel/test-https-immutable-options.js, which tested in
server2.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need a test like
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@refack done.