| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 73c0564 commit 391dc74
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -75,10 +75,12 @@ const { | |||
| 75 | 75 | ERR_HTTP_HEADERS_SENT, | |
| 76 | 76 | ERR_HTTP_INVALID_STATUS_CODE, | |
| 77 | 77 | ERR_HTTP_SOCKET_ENCODING, | |
| 78 | - ERR_INVALID_ARG_TYPE, | ||
| 79 | 78 | ERR_INVALID_ARG_VALUE, | |
| 80 | 79 | ERR_INVALID_CHAR | |
| 81 | 80 | } = codes; | |
| 81 | + const { | ||
| 82 | + kEmptyObject, | ||
| 83 | + } = require('internal/util'); | ||
| 82 | 84 | const { | |
| 83 | 85 | validateInteger, | |
| 84 | 86 | validateBoolean, | |
@@ -433,9 +435,6 @@ function storeHTTPOptions(options) { | |||
| 433 | 435 | validateBoolean(insecureHTTPParser, 'options.insecureHTTPParser'); | |
| 434 | 436 | this.insecureHTTPParser = insecureHTTPParser; | |
| 435 | 437 | ||
| 436 | - if (options.noDelay === undefined) | ||
| 437 | - options.noDelay = true; | ||
| 438 | - | ||
| 439 | 438 | const requestTimeout = options.requestTimeout; | |
| 440 | 439 | if (requestTimeout !== undefined) { | |
| 441 | 440 | validateInteger(requestTimeout, 'requestTimeout', 0); | |
@@ -502,17 +501,17 @@ function Server(options, requestListener) { | |||
| 502 | 501 | ||
| 503 | 502 | if (typeof options === 'function') { | |
| 504 | 503 | requestListener = options; | |
| 505 | - options = {}; | ||
| 506 | - } else if (options == null || typeof options === 'object') { | ||
| 507 | - options = { ...options }; | ||
| 504 | + options = kEmptyObject; | ||
| 505 | + } else if (options == null) { | ||
| 506 | + options = kEmptyObject; | ||
| 508 | 507 | } else { | |
| 509 | - throw new ERR_INVALID_ARG_TYPE('options', 'object', options); | ||
| 508 | + validateObject(options, 'options'); | ||
| 510 | 509 | } | |
| 511 | 510 | ||
| 512 | 511 | storeHTTPOptions.call(this, options); | |
| 513 | 512 | net.Server.call( | |
| 514 | 513 | this, | |
| 515 | - { allowHalfOpen: true, noDelay: options.noDelay, | ||
| 514 | + { allowHalfOpen: true, noDelay: options.noDelay ?? true, | ||
| 516 | 515 | keepAlive: options.keepAlive, | |
| 517 | 516 | keepAliveInitialDelay: options.keepAliveInitialDelay }); | |
| 518 | 517 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -53,25 +53,31 @@ let debug = require('internal/util/debuglog').debuglog('https', (fn) => { | |||
| 53 | 53 | debug = fn; | |
| 54 | 54 | }); | |
| 55 | 55 | const { URL, urlToHttpOptions, searchParamsSymbol } = require('internal/url'); | |
| 56 | + const { validateObject } = require('internal/validators'); | ||
| 56 | 57 | ||
| 57 | 58 | function Server(opts, requestListener) { | |
| 58 | 59 | if (!(this instanceof Server)) return new Server(opts, requestListener); | |
| 59 | 60 | ||
| 60 | 61 | if (typeof opts === 'function') { | |
| 61 | 62 | requestListener = opts; | |
| 62 | - opts = undefined; | ||
| 63 | - } | ||
| 64 | - opts = { ...opts }; | ||
| 65 | - | ||
| 66 | - if (!opts.ALPNProtocols) { | ||
| 67 | - // http/1.0 is not defined as Protocol IDs in IANA | ||
| 68 | - // https://www.iana.org/assignments/tls-extensiontype-values | ||
| 69 | - // /tls-extensiontype-values.xhtml#alpn-protocol-ids | ||
| 70 | - opts.ALPNProtocols = ['http/1.1']; | ||
| 63 | + opts = kEmptyObject; | ||
| 64 | + } else if (opts == null) { | ||
| 65 | + opts = kEmptyObject; | ||
| 66 | + } else { | ||
| 67 | + validateObject(opts, 'options'); | ||
| 71 | 68 | } | |
| 72 | 69 | ||
| 73 | 70 | FunctionPrototypeCall(storeHTTPOptions, this, opts); | |
| 74 | - FunctionPrototypeCall(tls.Server, this, opts, _connectionListener); | ||
| 71 | + FunctionPrototypeCall(tls.Server, this, | ||
| 72 | + { | ||
| 73 | + noDelay: true, | ||
| 74 | + // http/1.0 is not defined as Protocol IDs in IANA | ||
| 75 | + // https://www.iana.org/assignments/tls-extensiontype-values | ||
| 76 | + // /tls-extensiontype-values.xhtml#alpn-protocol-ids | ||
| 77 | + ALPNProtocols: ['http/1.1'], | ||
| 78 | + ...opts, | ||
| 79 | + }, | ||
| 80 | + _connectionListener); | ||
| 75 | 81 | ||
| 76 | 82 | this.httpAllowHalfOpen = false; | |
| 77 | 83 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,10 +27,7 @@ const http = require('http'); | |||
| 27 | 27 | const url = require('url'); | |
| 28 | 28 | const qs = require('querystring'); | |
| 29 | 29 | ||
| 30 | - // TODO: documentation does not allow Array as an option, so testing that | ||
| 31 | - // should fail, but currently http.Server does not typecheck further than | ||
| 32 | - // if `option` is `typeof object` - so we don't test that here right now | ||
| 33 | - const invalid_options = [ 'foo', 42, true ]; | ||
| 30 | + const invalid_options = [ 'foo', 42, true, [] ]; | ||
| 34 | 31 | ||
| 35 | 32 | invalid_options.forEach((option) => { | |
| 36 | 33 | assert.throws(() => { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -44,6 +44,15 @@ const serverCallback = common.mustCall(function(req, res) { | |||
| 44 | 44 | res.end(body); | |
| 45 | 45 | }); | |
| 46 | 46 | ||
| 47 | + const invalid_options = [ 'foo', 42, true, [] ]; | ||
| 48 | + invalid_options.forEach((option) => { | ||
| 49 | + assert.throws(() => { | ||
| 50 | + new https.Server(option); | ||
| 51 | + }, { | ||
| 52 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 53 | + }); | ||
| 54 | + }); | ||
| 55 | + | ||
| 47 | 56 | const server = https.createServer(options, serverCallback); | |
| 48 | 57 | ||
| 49 | 58 | server.listen(0, common.mustCall(() => { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments