Comparing version 4.2.1 to 4.2.2
@@ -99,3 +99,3 @@ 'use strict' | ||
if (!handler || typeof handler !== 'object') { | ||
throw new InvalidArgumentError('handler') | ||
throw new InvalidArgumentError('handler must be an object.') | ||
} | ||
@@ -105,7 +105,10 @@ | ||
if (!opts || typeof opts !== 'object') { | ||
throw new InvalidArgumentError('opts must be a object.') | ||
throw new InvalidArgumentError('opts must be an object.') | ||
} | ||
if (typeof opts.origin !== 'string' || opts.origin === '') { | ||
throw new InvalidArgumentError('opts.origin must be a non-empty string.') | ||
let key | ||
if (opts.origin && (typeof opts.origin === 'string' || opts.origin instanceof URL)) { | ||
key = String(opts.origin) | ||
} else { | ||
throw new InvalidArgumentError('opts.origin must be a non-empty string or URL.') | ||
} | ||
@@ -121,3 +124,3 @@ | ||
const ref = this[kClients].get(opts.origin) | ||
const ref = this[kClients].get(key) | ||
@@ -132,4 +135,4 @@ let dispatcher = ref ? ref.deref() : null | ||
this[kClients].set(opts.origin, new WeakRef(dispatcher)) | ||
this[kFinalizer].register(dispatcher, opts.origin) | ||
this[kClients].set(key, new WeakRef(dispatcher)) | ||
this[kFinalizer].register(dispatcher, key) | ||
} | ||
@@ -136,0 +139,0 @@ |
@@ -248,3 +248,3 @@ 'use strict' | ||
if (!handler || typeof handler !== 'object') { | ||
throw new InvalidArgumentError('handler') | ||
throw new InvalidArgumentError('handler must be an object') | ||
} | ||
@@ -254,3 +254,3 @@ | ||
if (!opts || typeof opts !== 'object') { | ||
throw new InvalidArgumentError('opts must be a object.') | ||
throw new InvalidArgumentError('opts must be an object.') | ||
} | ||
@@ -1098,3 +1098,3 @@ | ||
// Resolve ipv6 | ||
if (hostname.startsWith('[')) { | ||
if (hostname[0] === '[') { | ||
const idx = hostname.indexOf(']') | ||
@@ -1400,6 +1400,2 @@ | ||
// TODO: An HTTP/1.1 user agent MUST NOT preface | ||
// or follow a request with an extra CRLF. | ||
// https://tools.ietf.org/html/rfc7230#section-3.5 | ||
let header | ||
@@ -1406,0 +1402,0 @@ |
@@ -82,5 +82,5 @@ 'use strict' | ||
.once(protocol === 'https:' ? 'secureConnect' : 'connect', function () { | ||
clearTimeout(timeout) | ||
if (callback) { | ||
clearTimeout(timeout) | ||
const cb = callback | ||
@@ -92,2 +92,4 @@ callback = null | ||
.on('error', function (err) { | ||
clearTimeout(timeout) | ||
if (callback) { | ||
@@ -94,0 +96,0 @@ const cb = callback |
@@ -100,32 +100,4 @@ 'use strict' | ||
if (typeof handler.onConnect !== 'function') { | ||
throw new InvalidArgumentError('invalid onConnect method') | ||
} | ||
util.validateHandler(handler, method, upgrade) | ||
if (typeof handler.onError !== 'function') { | ||
throw new InvalidArgumentError('invalid onError method') | ||
} | ||
if (typeof handler.onBodySent !== 'function' && handler.onBodySent !== undefined) { | ||
throw new InvalidArgumentError('invalid onBodySent method') | ||
} | ||
if (this.upgrade || this.method === 'CONNECT') { | ||
if (typeof handler.onUpgrade !== 'function') { | ||
throw new InvalidArgumentError('invalid onUpgrade method') | ||
} | ||
} else { | ||
if (typeof handler.onHeaders !== 'function') { | ||
throw new InvalidArgumentError('invalid onHeaders method') | ||
} | ||
if (typeof handler.onData !== 'function') { | ||
throw new InvalidArgumentError('invalid onData method') | ||
} | ||
if (typeof handler.onComplete !== 'function') { | ||
throw new InvalidArgumentError('invalid onComplete method') | ||
} | ||
} | ||
this.servername = util.getServerName(this.host) | ||
@@ -132,0 +104,0 @@ |
@@ -61,3 +61,3 @@ 'use strict' | ||
? url.port | ||
: { 'http:': 80, 'https:': 443 }[url.protocol] | ||
: (url.protocol === 'https:' ? 443 : 80) | ||
const origin = url.origin != null | ||
@@ -79,3 +79,3 @@ ? url.origin | ||
if (/\/.+/.test(url.pathname) || url.search || url.hash) { | ||
if (url.pathname !== '/' || url.search || url.hash) { | ||
throw new InvalidArgumentError('invalid url') | ||
@@ -96,3 +96,3 @@ } | ||
if (servername.startsWith('[')) { | ||
if (servername[0] === '[') { | ||
const idx = servername.indexOf(']') | ||
@@ -194,2 +194,38 @@ | ||
function validateHandler (handler, method, upgrade) { | ||
if (!handler || typeof handler !== 'object') { | ||
throw new InvalidArgumentError('handler must be an object') | ||
} | ||
if (typeof handler.onConnect !== 'function') { | ||
throw new InvalidArgumentError('invalid onConnect method') | ||
} | ||
if (typeof handler.onError !== 'function') { | ||
throw new InvalidArgumentError('invalid onError method') | ||
} | ||
if (typeof handler.onBodySent !== 'function' && handler.onBodySent !== undefined) { | ||
throw new InvalidArgumentError('invalid onBodySent method') | ||
} | ||
if (upgrade || method === 'CONNECT') { | ||
if (typeof handler.onUpgrade !== 'function') { | ||
throw new InvalidArgumentError('invalid onUpgrade method') | ||
} | ||
} else { | ||
if (typeof handler.onHeaders !== 'function') { | ||
throw new InvalidArgumentError('invalid onHeaders method') | ||
} | ||
if (typeof handler.onData !== 'function') { | ||
throw new InvalidArgumentError('invalid onData method') | ||
} | ||
if (typeof handler.onComplete !== 'function') { | ||
throw new InvalidArgumentError('invalid onComplete method') | ||
} | ||
} | ||
} | ||
module.exports = { | ||
@@ -210,3 +246,4 @@ nop, | ||
deepClone, | ||
isBuffer | ||
isBuffer, | ||
validateHandler | ||
} |
@@ -15,2 +15,4 @@ 'use strict' | ||
util.validateHandler(handler, opts.method, opts.upgrade) | ||
this.dispatcher = dispatcher | ||
@@ -29,3 +31,2 @@ this.location = null | ||
if (util.bodyLength(opts.body) === 0) { | ||
// TODO (fix): Write a comment why this is needed? | ||
opts.body | ||
@@ -32,0 +33,0 @@ .on('data', function () { |
@@ -165,3 +165,3 @@ 'use strict' | ||
if (!handler || typeof handler !== 'object') { | ||
throw new InvalidArgumentError('handler') | ||
throw new InvalidArgumentError('handler must be an object') | ||
} | ||
@@ -168,0 +168,0 @@ |
{ | ||
"name": "undici", | ||
"version": "4.2.1", | ||
"version": "4.2.2", | ||
"description": "An HTTP/1.1 client, written from scratch for Node.js", | ||
@@ -5,0 +5,0 @@ "homepage": "https://undici.nodejs.org", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
431005
5117