-
Notifications
You must be signed in to change notification settings - Fork 306
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't use deprecated url.parse function (#4743)
- Loading branch information
Showing
2 changed files
with
39 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
packages/dd-trace/src/exporters/common/url-to-http-options-polyfill.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict' | ||
|
||
const { urlToHttpOptions } = require('url') | ||
|
||
// TODO: Remove `urlToHttpOptions` polyfill once we drop support for the older Cypress versions that uses a built-in | ||
// version of Node.js doesn't include that function. | ||
module.exports = { | ||
urlToHttpOptions: urlToHttpOptions ?? function (url) { | ||
const { hostname, pathname, port, username, password, search } = url | ||
const options = { | ||
__proto__: null, | ||
...url, // In case the url object was extended by the user. | ||
protocol: url.protocol, | ||
hostname: typeof hostname === 'string' && hostname.startsWith('[') | ||
? hostname.slice(1, -1) | ||
: hostname, | ||
hash: url.hash, | ||
search, | ||
pathname, | ||
path: `${pathname || ''}${search || ''}`, | ||
href: url.href | ||
} | ||
if (port !== '') { | ||
options.port = Number(port) | ||
} | ||
if (username || password) { | ||
options.auth = `${decodeURIComponent(username)}:${decodeURIComponent(password)}` | ||
} | ||
return options | ||
} | ||
} |