MCPcopy Index your code
hub / github.com/nodejs/node / urlToHttpOptions

Function urlToHttpOptions

lib/internal/url.js:1447–1470  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

1445 * @returns {Record<string, unknown>}
1446 */
1447function 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
1472function getPathFromURLWin32(url) {
1473 const hostname = url.hostname;

Callers 3

ClientRequestFunction · 0.85
requestFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…