exp-fetch
Advanced tools
Comparing version
73
index.js
@@ -17,3 +17,2 @@ "use strict"; | ||
const isRedirect = require("./lib/isRedirect"); | ||
const ensureAbsoluteUrl = require("./lib/ensureAbsoluteUrl"); | ||
const currentAppConfig = require("./lib/currentAppConfig"); | ||
@@ -233,3 +232,3 @@ | ||
if (redirectCount++ < maximumNumberOfRedirects) { | ||
const location = ensureAbsoluteUrl(response.headers, url); | ||
const location = new URL(response.headers.location, url).toString(); | ||
return performRequest(location, headers, explicitTimeout, method, body, redirectCount, callback); | ||
@@ -245,44 +244,48 @@ } else { | ||
function fetch(method, options, optionalBody, resultCallback) { | ||
let url = options; | ||
if (typeof optionalBody === "function") { | ||
resultCallback = optionalBody; | ||
optionalBody = null; | ||
} | ||
const extraHeaders = {}; | ||
try { | ||
let url = options; | ||
if (getCorrelationId) { | ||
const correlationId = getCorrelationId(); | ||
if (correlationId) { | ||
extraHeaders[correlationIdHeader] = correlationId; | ||
const extraHeaders = {}; | ||
if (getCorrelationId) { | ||
const correlationId = getCorrelationId(); | ||
if (correlationId) { | ||
extraHeaders[correlationIdHeader] = correlationId; | ||
} | ||
} | ||
} | ||
const headers = Object.assign({}, globalHeaders, options.headers, extraHeaders); | ||
let explicitTimeout = null; | ||
if (typeof options === "object") { | ||
if (options.url) { | ||
url = options.url; | ||
const headers = Object.assign({}, globalHeaders, options.headers, extraHeaders); | ||
let explicitTimeout = null; | ||
if (typeof options === "object") { | ||
if (options.url) { | ||
url = options.url; | ||
} | ||
if (options.timeout) { | ||
explicitTimeout = options.timeout; | ||
} | ||
} | ||
if (options.timeout) { | ||
explicitTimeout = options.timeout; | ||
if (currentAppConfig.name) { | ||
headers["x-exp-fetch-appname"] = currentAppConfig.name; | ||
} | ||
} | ||
if (currentAppConfig.name) { | ||
headers["x-exp-fetch-appname"] = currentAppConfig.name; | ||
if (resultCallback) { | ||
performRequest(url, headers, explicitTimeout, method, optionalBody, 0, resultCallback, onRequestInit); | ||
} else { | ||
return new Promise((resolve, reject) => { | ||
performRequest(url, headers, explicitTimeout, method, optionalBody, 0, (err, content) => { | ||
if (err) return reject(err); | ||
return resolve(content); | ||
}, onRequestInit); | ||
}); | ||
} | ||
} catch (err) { | ||
return resultCallback ? resultCallback(err) : Promise.reject(err); | ||
} | ||
if (typeof optionalBody === "function") { | ||
resultCallback = optionalBody; | ||
optionalBody = null; | ||
} | ||
if (resultCallback) { | ||
performRequest(url, headers, explicitTimeout, method, optionalBody, 0, resultCallback, onRequestInit); | ||
} else { | ||
return new Promise((resolve, reject) => { | ||
performRequest(url, headers, explicitTimeout, method, optionalBody, 0, (err, content) => { | ||
if (err) return reject(err); | ||
return resolve(content); | ||
}, onRequestInit); | ||
}); | ||
} | ||
function onRequestInit() { | ||
@@ -289,0 +292,0 @@ if (behavior.onRequestInit) { |
{ | ||
"name": "exp-fetch", | ||
"version": "5.3.1", | ||
"version": "5.3.2", | ||
"description": "A small pluggable fetch lib", | ||
@@ -26,10 +26,10 @@ "main": "index.js", | ||
"chai": "^4.3.6", | ||
"eslint": "^8.3.0", | ||
"eslint-config-exp": "^0.2.0", | ||
"mocha": "^9.2.0", | ||
"nock": "^13.2.2" | ||
"eslint": "^8.26.0", | ||
"eslint-config-exp": "^0.5.0", | ||
"mocha": "^10.1.0", | ||
"nock": "^13.2.9" | ||
}, | ||
"dependencies": { | ||
"clone": "^2.1.1", | ||
"exp-asynccache": "^2.0.0", | ||
"exp-asynccache": "^3.2.0", | ||
"got": "^11.8.3", | ||
@@ -36,0 +36,0 @@ "lru-cache": "^6.0.0", |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
25077
-1.22%13
-7.14%415
-1.89%+ Added
- Removed
- Removed
- Removed
Updated