目录
v-schhabra

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

14天前247次提交

Build Status

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

  • REST and HTTP client with TypeScript generics and async/await/Promises
  • Typings included so no need to acquire separately (great for intellisense and no versioning drift)
  • Basic, Bearer and NTLM Support out of the box. Extensible handlers for others.
  • Proxy support
  • Certificate support (Self-signed server and client cert)
  • Redirects supported

Intellisense and compile support:

intellisense

Install

npm install typed-rest-client --save

Or to install the latest preview:

npm install typed-rest-client@preview --save

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.

  • A request that successfully executes resulting in a 404, 500 etc… will return a response object with a status code and a body.
  • Redirects (3xx) will be followed by default.

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.

  • A 200 will be success.
  • Redirects (3xx) will be followed.
  • A 404 will not throw but the result object will be null and the result statusCode will be set.
  • Other 4xx and 5xx errors will throw. The status code will be attached to the error object. If a RESTful error object is returned ({ 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:

export NODE_DEBUG=http

or

set NODE_DEBUG=http

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:

$ npm run build

To run all tests:

$ npm test

To just run unit tests:

$ npm run units

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.

邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9 京公网安备 11010802047560号