* Utility function that converts a URL object into an ordinary options object * as expected by the `http.request` and `https.request` APIs. * @param {URL} url * @returns {Record }
(url)
| 1445 | * @returns {Record<string, unknown>} |
| 1446 | */ |
| 1447 | function urlToHttpOptions(url) { |
| 1448 | validateObject(url, 'url', kValidateObjectAllowObjects); |
| 1449 | const { hostname, pathname, port, username, password, search } = url; |
| 1450 | const options = { |
| 1451 | __proto__: null, |
| 1452 | ...url, // In case the url object was extended by the user. |
| 1453 | protocol: url.protocol, |
| 1454 | hostname: hostname && hostname[0] === '[' ? |
| 1455 | StringPrototypeSlice(hostname, 1, -1) : |
| 1456 | hostname, |
| 1457 | hash: url.hash, |
| 1458 | search: search, |
| 1459 | pathname: pathname, |
| 1460 | path: `${pathname || ''}${search || ''}`, |
| 1461 | href: url.href, |
| 1462 | }; |
| 1463 | if (port !== '') { |
| 1464 | options.port = Number(port); |
| 1465 | } |
| 1466 | if (username || password) { |
| 1467 | options.auth = `${decodeURIComponent(username)}:${decodeURIComponent(password)}`; |
| 1468 | } |
| 1469 | return options; |
| 1470 | } |
| 1471 | |
| 1472 | function getPathFromURLWin32(url) { |
| 1473 | const hostname = url.hostname; |
no outgoing calls
no test coverage detected
searching dependent graphs…