Remove Deprecated use of url.parse - #389
Conversation
There was a problem hiding this comment.
Pull request overview
This PR migrates from the deprecated Node.js url.parse() API (deprecated in Node 24 as DEP0169) to the WHATWG URL() constructor. The changes update URL parsing logic across the HTTP client library to use the modern URL API while attempting to preserve existing behavior.
Changes:
- Replaced
url.parse()withnew URL()constructor throughout the codebase - Updated type signatures from
url.UrltoURLin interfaces and method signatures - Refactored URL merging logic in
Util.getUrl()to handle relative and absolute URLs with the new API - Added error handling for invalid URLs during parsing
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| lib/Util.ts | Refactored getUrl() function to use URL constructor, with logic to detect and handle relative vs absolute resource URLs, manual URL construction for path merging |
| lib/Interfaces.ts | Updated IRequestInfo interface to use URL type instead of url.Url |
| lib/HttpClient.ts | Updated all url.parse() calls to new URL(), changed type signatures, replaced url.format() with .href property |
| test/units/utiltests.ts | Updated test cases to use new URL() instead of url.parse() |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 8 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
| } else { | ||
| // Resource is a relative path - merge with base using path.resolve | ||
| const protocol = base.protocol; | ||
| const encodedUsername = base.username ? encodeURIComponent(base.username) : ''; |
There was a problem hiding this comment.
username and password here can contain special characters?
There was a problem hiding this comment.
Yes, urlstores username/password in decoded form (e.g., %40 becomes @). When we reconstruct the URL string manually, we must use
encodeURIComponent() to re-encode special character
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
1 similar comment
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
dc853e3 to
8d411cc
Compare
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
| } | ||
|
|
||
| private _isMatchInBypassProxyList(parsedUrl: url.Url): Boolean { | ||
| private _isMatchInBypassProxyList(parsedUrl: URL): Boolean { |
There was a problem hiding this comment.
can we please check if we can use boolean here that is primitive type instead of object Type Boolean?
| // Copyright (c) Microsoft. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| import url = require("url"); |
There was a problem hiding this comment.
can we please check if we need this url import in this file and other file since we removed url.parse?
Deprecation in Node 24: https://nodejs.org/api/deprecations.html#DEP0169
This PR updates use of url.parse to Safer
New URL()Impacts how request object is formed by rest-client