-
Notifications
You must be signed in to change notification settings - Fork 30k
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
https: make opts optional & immutable when create #13599
Changes from 3 commits
26d4efb
2c7ff7b
b3a1ac6
9414765
c798af8
5de8cf2
dc2291c
2232fad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,9 +31,15 @@ const inherits = util.inherits; | |
const debug = util.debuglog('https'); | ||
const { urlToOptions, searchParamsSymbol } = require('internal/url'); | ||
|
||
function Server(opts, requestListener) { | ||
function Server(opts = {}, requestListener) { | ||
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. Note that using default values is potentially a breaking change given that it changes the value of 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. Shall I delete the default value? |
||
if (!(this instanceof Server)) return new Server(opts, requestListener); | ||
|
||
if (typeof opts === 'function') { | ||
requestListener = opts; | ||
opts = undefined; | ||
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 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. @yorkie, Because I think 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. Then I think you would make the 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. The problem is Do you mean that? ...
const realOpts = util._extend({}, opts); 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. The mean problem is the default value, removing that like https://github.com/nodejs/node/pull/13599/files#r121620077 works for me :) |
||
} | ||
opts = opts ? Object.assign({}, opts) : {}; | ||
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. I think you can change this to opts = Object.assign({}, 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,22 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
|
||
const assert = require('assert'); | ||
const https = require('https'); | ||
const tls = require('tls'); | ||
|
||
const dftProtocol = {}; | ||
tls.convertNPNProtocols([ 'http/1.1', 'http/1.0' ], dftProtocol); | ||
|
||
const opts = { foo: 'bar' }; | ||
const server1 = https.createServer(opts); | ||
|
||
assert.deepStrictEqual(opts, { foo: 'bar' }); | ||
assert.strictEqual(server1.NPNProtocols.compare(dftProtocol.NPNProtocols), 0); | ||
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. I think it should suffice to just compare the assert.strictEqual(server1.NPNProtocols, dftProtocol.NPNProtocols); 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. @mscdex I think we can't, because 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. Ah ok I see it now. Perhaps we should at least choose a different set of protocols then, so as to differentiate from the default NPN protocols (perhaps just use one protocol?). |
||
|
||
const mustNotCall = common.mustNotCall(); | ||
const server2 = https.createServer(mustNotCall); | ||
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. The comment below doesn't match the behavior of this line. If we're testing no arguments, it should just be Otherwise we could add a separate test below for no arguments. |
||
|
||
assert.strictEqual(server2.NPNProtocols.compare(dftProtocol.NPNProtocols), 0); | ||
assert.strictEqual(mustNotCall, server2._events.request); | ||
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. Can we replace this with assert.strictEqual(server2.listeners('request'), 1);
assert.strictEqual(server2.listeners('request')[0], mustNotCall); |
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.