Conversation
There was a problem hiding this comment.
Pull request overview
This PR removes the deprecated url.parse() API (deprecated since Node.js 11) and replaces it with the modern WHATWG URL API, which is globally available in Node.js 18+.
Key Changes:
- Replaced
url.parse(requestUrl)withnew URL(requestUrl)constructor - Updated
getRequestOptionsFromUrl()to accept WHATWG URL objects and adapted property access patterns - Removed the deprecated
urlmodule import
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| path: url.path, | ||
| port: url.port, | ||
| path: url.pathname + url.search, | ||
| port: url.port || null, |
There was a problem hiding this comment.
The port handling logic is incorrect. The WHATWG URL API's port property returns an empty string ("") when no explicit port is specified, not a falsy value. Using url.port || null will incorrectly set the port to null even when a valid port exists if the port is "0", and will correctly handle empty strings but for the wrong reason.
The correct approach is to check for an empty string explicitly: url.port ? url.port : null or url.port !== '' ? url.port : null. This ensures that:
- Valid ports (including "0") are passed through
- Empty strings (no explicit port) become null
- The http.RequestOptions receives the appropriate value
| port: url.port || null, | |
| port: url.port !== '' ? url.port : null, |
Summary
url.parse()has been deprecated since Node.js 11. The listed support, Node.js 18+ (per package.json), means we should use the modern WHATWG URL API which is globally available.