Skip to content

Commit

Permalink
fix: default port
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Dec 10, 2024
1 parent 30f2bef commit c462dda
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,17 @@ export class RequestHandler {
export function request(dispatch, url, opts) {
return new Promise((resolve) => {
if (typeof url === 'string') {
opts = { url: new URL(url), ...opts }
opts = { ...opts, url: new URL(url) }
} else if (url instanceof URL) {
opts = { url, ...opts }
} else if (typeof url.origin === 'string' && typeof (url.path ?? url.pathname) === 'string') {
opts = opts ? { ...url, ...opts } : url
opts = { ...opts, url: new URL(url) }
} else if (typeof url.origin === 'string' && url.length > 0) {
opts = { ...opts, url }
} else {
throw new Error('invalid url')
}

if (opts == null && typeof url === 'object' && url != null) {
url.protocol ??= 'http:'
opts = { protocol: 'http:', ...url }
}
opts.url.protocol ??= 'http'
opts.url.port ??= opts.url.protocol === 'https:' ? '443' : '80'

dispatch(opts, new RequestHandler(opts, resolve))
})
Expand Down

0 comments on commit c462dda

Please sign in to comment.