@vonage/vetch
Advanced tools
Comparing version 1.4.0 to 1.5.0
@@ -24,3 +24,4 @@ /// <reference types="node" /> | ||
timeout?: number; | ||
appendUserAgent?: string; | ||
agent?: boolean | http.Agent | https.Agent | ((parsedUrl: URL) => boolean | https.Agent | http.Agent); | ||
} |
@@ -25,5 +25,18 @@ "use strict"; | ||
async _defaultAdapter(opts) { | ||
const res = await (0, node_fetch_1.default)(opts.url, opts); | ||
const data = await this.getResponseData(opts, res); | ||
return this.createResponse(opts, res, data); | ||
const { timeout } = opts; | ||
let timeoutId = null; | ||
const fetchConfig = opts; | ||
if (timeout) { | ||
const controller = new AbortController(); | ||
timeoutId = setTimeout(() => controller.abort(), timeout); | ||
fetchConfig.signal = controller.signal; | ||
} | ||
try { | ||
const res = await (0, node_fetch_1.default)(opts.url, fetchConfig); | ||
const data = await this.getResponseData(opts, res); | ||
return this.createResponse(opts, res, data); | ||
} | ||
finally { | ||
clearTimeout(timeoutId); | ||
} | ||
} | ||
@@ -91,9 +104,13 @@ async request(opts = {}) { | ||
// Set our user agent | ||
opts.headers['user-agent'] = `@vonage/server-sdk/3.0.0 node/${process.version.replace('v', '')}`; | ||
opts.headers['user-agent'] = [ | ||
`@vonage/server-sdk/3.0.0`, | ||
` node/${process.version.replace('v', '')}`, | ||
opts.appendUserAgent ? ` ${opts.appendUserAgent}` : '', | ||
].join(''); | ||
// Allow a custom timeout to be used | ||
const httpAgent = new http_1.default.Agent({ | ||
timeout: this.defaults.timeout, | ||
timeout: opts.timeout, | ||
}); | ||
const httpsAgent = new https_1.default.Agent({ | ||
timeout: this.defaults.timeout, | ||
timeout: opts.timeout, | ||
}); | ||
@@ -100,0 +117,0 @@ opts.agent = (parsedUrl) => { |
{ | ||
"name": "@vonage/vetch", | ||
"version": "1.4.0", | ||
"version": "1.5.0", | ||
"description": "Vonage package for server side fetch.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/vonage/vonage-node-sdk/tree/master/packages/vetch#readme", |
Sorry, the diff of this file is not supported yet
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
20879
310