Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/api/https.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,7 +46,7 @@ added: v8.0.0

See [`http.Server#keepAliveTimeout`][].

## https.createServer(options[, requestListener])
## https.createServer([options][, requestListener])
Copy link
Contributor

@mscdexmscdexJun 10, 2017

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, since tls.Server() will still require a configuration (a certificate and key at minimum). The benefit of guarding early before tls.Server() is called is to avoid strange JavaScript runtime errors. Huh... I take that back, it doesn't seem to enforce a minimum configuration...

Copy link
Contributor

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.

Copy link
ContributorAuthor

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a test like

// validate that `createServer` can work with no argumentsconstserver2=https.createServer();assert.ok(server2);assert.strictEqual(server1.NPNProtocols.compare(dftProtocol.NPNProtocols),0);

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@refack done.

<!-- YAML
added: v0.3.4
-->
Expand Down
6 changes: 6 additions & 0 deletions lib/https.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit: The optional value is an object, but here reset to undefined, this does not appear consistent :)

Copy link
ContributorAuthor

@XadillaXXadillaXJun 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yorkie, Because I think util._extend({}, undefined) performance is better than util._extend({},{})

Copy link
Contributor

@yorkieyorkieJun 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then I think you would make the opts default be unset as well for performance. BTW perf is not that crucial here than consistence and readability, this constructor needn't be called too much times in any of applications :)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is opts = util._extend({}, opts); shows it's not a consistent.

Do you mean that?

... constrealOpts=util._extend({},opts);

Copy link
Contributor

Choose a reason for hiding this comment

The 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 = util._extend({}, opts);

if (process.features.tls_npn && !opts.NPNProtocols){
opts.NPNProtocols = ['http/1.1', 'http/1.0'];
}
Expand Down
44 changes: 44 additions & 0 deletions test/parallel/test-https-argument-of-creating.js
Original file line numberDiff line numberDiff 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);
}