Replace deprecated url.parse() with WHATWG URL constructor (#399)
- Replace deprecated url.parse() with WHATWG URL constructor
Migrate all usages of the legacy url.parse() API to the modern URL constructor (WHATWG URL Standard). url.parse() is deprecated since Node 11 and emits warnings in Node 22+.
Changes:
- lib/HttpClient.ts: Replace url.parse() with new URL(), ensure proxy tunnel port is always numeric with safe default for default ports
- lib/Interfaces.ts: Change IRequestInfo.parsedUrl type from url.Url to URL
- lib/Util.ts: Rewrite getUrl() to use new URL() with trailing-slash normalization for correct relative path resolution
- test/units/utiltests.ts: Update test helpers to use new URL()
The URL constructor is stable since Node 10 and works across all current and future Node.js versions.
Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com
- Replace url.parse() in ntlm.js with new URL()
Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com
updated tests
Add comprehensive tests for proxy tunnel, redirect, and getUrl edge cases
- Add 12 proxy tunnel tests: port as number, default ports (80/443), HTTPS through HTTP proxy, auth with special chars, bypass, env proxy, keepAlive agent caching, prepareRequest port parsing and defaults
- Add 3 redirect tests: relative path, relative with .., absolute cross-origin
- Add 8 getUrl edge case tests: absolute/relative/rooted resource, trailing slash, query params, port, fragment
All 106 tests pass.
Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com
Adjust unit HTTP tests for stability
addressed review comments
modified logic to handle auth and other edge case scenarioes and added test cases as well
Remove legacy URL adapter, ship breaking change as 3.0.0
- Remove ILegacyParsedUrl interface and _toLegacyParsedUrl() method
- IRequestInfo.parsedUrl is now WHATWG URL directly (breaking change)
- Remove rawRequestUrl parameter from _prepareRequest()
- Remove requestUrl field from IRequestInfo (redundant with parsedUrl)
- Clean up ntlm.ts handler references
- Remove legacy adapter tests (7 tests removed, 108 remain passing)
- Keep try/catch guards on new URL() for descriptive errors
- Keep tunnel port fix: Number(port) || default
BREAKING CHANGE: IRequestInfo.parsedUrl is now a WHATWG URL object. Properties .auth, .path, .query (from url.Url) no longer exist. Use .username/.password, .pathname+.search, .searchParams instead.
Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com
- Add try/catch guards to Util.ts and fix Boolean to boolean return type
- Wrap new URL() calls in Util.ts getUrl() with try/catch for consistent error handling (descriptive messages instead of raw TypeError)
- Fix _isMatchInBypassProxyList return type from Boolean to boolean
Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com
- Remove try/catch guards around new URL() calls
Per reviewer feedback: since this is a breaking 3.0.0 release, consumers are expected to pass valid URLs. Let new URL() throw naturally rather than wrapping every call site with redundant error handling.
Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com
Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com Co-authored-by: D Kodanda Ramudu (LTIMindtree Limited) v-dko@microsoft.com
版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9
京公网安备 11010802047560号
Typed REST and HTTP Client with TypeScript Typings
A lightweight REST and HTTP client optimized for use with TypeScript with generics and async await.
Features
Intellisense and compile support:
Install
Or to install the latest preview:
Samples
See the samples for complete coding examples. Also see the REST and HTTP tests for detailed examples.
Errors
HTTP
The HTTP client does not throw unless truly exceptional.
See HTTP tests for detailed examples.
REST
The REST client is a high-level client which uses the HTTP client. Its responsibility is to turn a body into a typed resource object.
{ message: xxx}), then the error message will be that. Otherwise, it will be a generic,Failed Request: (xxx).See REST tests for detailed examples.
Debugging
To enable detailed console logging of all HTTP requests and responses, set the NODE_DEBUG environment varible:
or
Node support
v2 - [current, maintained] - Supports node 16 and above v1 - End Of Life, for Node < 16, contains security vulnerabilities, use at your own risk
Contributing
To contribute to this repository, see the contribution guide
To build:
To run all tests:
To just run unit tests:
Code of Conduct
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
Security Issues
Do you think there might be a security issue? Have you been phished or identified a security vulnerability? Please don’t report it here - let us know by sending an email to secure@microsoft.com.