-
Notifications
You must be signed in to change notification settings - Fork 232
Change code to use url.URL instead of url.parse #1254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
We can't upgrade to the new version of 'standard' currently because we still use the deprecated `url.parse` API in several locations (see issue no elastic#1254). But to ensure fewer merge conflicts between the 2.x and the upcoming 3.x branch), we'll fix as many future linting issues as possible already now.
We can't upgrade to the new version of 'standard' currently because we still use the deprecated `url.parse` API in several locations (see issue no #1254). But to ensure fewer merge conflicts between the 2.x and the upcoming 3.x branch, we'll fix as many future linting issues as possible already now.
@watson I'm happy to take this issue. |
@yuxizhe that would be really helpful. But it might be a bit tricky though... before I opened this issue, I checked if I could easily do it myself. But it's unfortunately not a 1-to-1 replacement due to the differences in how the two functions behave. But we can discuss how to best implement it if you still want to take it on |
@watson Yes, I reread the docs https://nodejs.org/api/url.html#url_url_strings_and_url_objects. I search in this repo find there are a few places where we use Except for the code in apm-agent-nodejs/lib/instrumentation/http-shared.js Lines 83 to 95 in 248c945
Object.assign(options, URL) mix options with URL in a different format { [Symbol(context)]:
URLContext {
flags: 912,
scheme: 'https:',
username: '',
password: '',
host: 'aaa.com',
port: null,
path: [ 'a', 'b' ],
query: 'a=1',
fragment: null },
[Symbol(query)]: URLSearchParams { 'a' => '1' } } So in this place I won't simply replace it with URL, function formatURL (item) {
return {
href: item.href,
pathname: item.pathname,
protocol: item.protocol,
host: item.host,
port: item.port,
hostname: item.hostname,
hash: item.hash,
search: item.search,
}
}
// NOTE: This will also stringify and parse URL instances
// to a format which can be mixed into the options object.
function ensureUrl (v) {
if (url.URL && (v instanceof url.URL || typeof v === 'string')) {
const urlItem = new URL(v.toString())
return formatURL(urlItem)
} else if (typeof v === 'string') {
return url.parse(v)
} else {
return v
}
} |
Oh, there is another problem. Relative URLs in WHATWG URL API nodejs/node#12682 I prefer to use this one |
Oh nice, I didn't know you could put in |
I think your approach in the code you posted above is good. If you can throw together a PR we can take it from there 😃 |
url.parse
is a deprecated core API. We should update our code to useurl.URL
instead.The text was updated successfully, but these errors were encountered: