@podium/client
Advanced tools
Comparing version 5.1.15 to 5.1.16
@@ -0,1 +1,9 @@ | ||
## [5.1.16](https://github.com/podium-lib/client/compare/v5.1.15...v5.1.16) (2024-10-17) | ||
### Bug Fixes | ||
* use AbortController instead of AbortSignal to avoid unhandled exception ([#412](https://github.com/podium-lib/client/issues/412)) ([ebdfc74](https://github.com/podium-lib/client/commit/ebdfc742a44acb3891ee7e2f38adde5317e8e8d0)) | ||
* use AbortSignal to ensure timeouts are respected ([3f970ed](https://github.com/podium-lib/client/commit/3f970ed5c3a5607615880cfe9ebee58409cd5ae0)) | ||
## [5.1.15](https://github.com/podium-lib/client/compare/v5.1.14...v5.1.15) (2024-10-14) | ||
@@ -2,0 +10,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { request } from 'undici'; | ||
import { request as undiciRequest } from 'undici'; | ||
@@ -10,3 +10,2 @@ /** | ||
* @property {number} [timeout] | ||
* @property {number} [bodyTimeout] | ||
* @property {object} [query] | ||
@@ -17,2 +16,6 @@ * @property {import('http').IncomingHttpHeaders} [headers] | ||
export default class HTTP { | ||
constructor(requestFn = undiciRequest) { | ||
this.requestFn = requestFn; | ||
} | ||
/** | ||
@@ -24,8 +27,21 @@ * @param {string} url | ||
async request(url, options) { | ||
const { statusCode, headers, body } = await request( | ||
new URL(url), | ||
options, | ||
); | ||
return { statusCode, headers, body }; | ||
const abortController = new AbortController(); | ||
const timeoutId = setTimeout(() => { | ||
abortController.abort(); | ||
}, options.timeout || 1000); | ||
try { | ||
const { statusCode, headers, body } = await this.requestFn( | ||
new URL(url), | ||
{ | ||
...options, | ||
signal: abortController.signal, | ||
}, | ||
); | ||
return { statusCode, headers, body }; | ||
} finally { | ||
clearTimeout(timeoutId); | ||
} | ||
} | ||
} |
@@ -139,3 +139,3 @@ import { pipeline } from 'stream'; | ||
rejectUnauthorized: outgoing.rejectUnauthorized, | ||
bodyTimeout: outgoing.timeout, | ||
timeout: outgoing.timeout, | ||
method: 'GET', | ||
@@ -271,2 +271,3 @@ query: outgoing.reqOptions.query, | ||
// @ts-ignore | ||
pipeline([body, outgoing], (err) => { | ||
@@ -273,0 +274,0 @@ if (err) { |
{ | ||
"name": "@podium/client", | ||
"version": "5.1.15", | ||
"version": "5.1.16", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -8,3 +8,2 @@ /** | ||
* @property {number} [timeout] | ||
* @property {number} [bodyTimeout] | ||
* @property {object} [query] | ||
@@ -14,2 +13,4 @@ * @property {import('http').IncomingHttpHeaders} [headers] | ||
export default class HTTP { | ||
constructor(requestFn?: typeof undiciRequest); | ||
requestFn: typeof undiciRequest; | ||
/** | ||
@@ -28,5 +29,5 @@ * @param {string} url | ||
timeout?: number; | ||
bodyTimeout?: number; | ||
query?: object; | ||
headers?: import('http').IncomingHttpHeaders; | ||
}; | ||
import { request as undiciRequest } from 'undici'; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
173681
2491