Skip to content

Commit c462dda

Browse files
committed
fix: default port
1 parent 30f2bef commit c462dda

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

lib/request.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,17 @@ export class RequestHandler {
151151
export function request(dispatch, url, opts) {
152152
return new Promise((resolve) => {
153153
if (typeof url === 'string') {
154-
opts = { url: new URL(url), ...opts }
154+
opts = { ...opts, url: new URL(url) }
155155
} else if (url instanceof URL) {
156-
opts = { url, ...opts }
157-
} else if (typeof url.origin === 'string' && typeof (url.path ?? url.pathname) === 'string') {
158-
opts = opts ? { ...url, ...opts } : url
156+
opts = { ...opts, url: new URL(url) }
157+
} else if (typeof url.origin === 'string' && url.length > 0) {
158+
opts = { ...opts, url }
159+
} else {
160+
throw new Error('invalid url')
159161
}
160162

161-
if (opts == null && typeof url === 'object' && url != null) {
162-
url.protocol ??= 'http:'
163-
opts = { protocol: 'http:', ...url }
164-
}
163+
opts.url.protocol ??= 'http'
164+
opts.url.port ??= opts.url.protocol === 'https:' ? '443' : '80'
165165

166166
dispatch(opts, new RequestHandler(opts, resolve))
167167
})

0 commit comments

Comments
 (0)