Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
}
if (connection.user != null && connection.password != null) {
if (url.substring(0, 6) !== "https:" && connection.allowInsecureAuthentication !== true) {
logger.throwError(
"basic authentication requires a secure https url",
Logger.errors.INVALID_ARGUMENT,
{ argument: "url", url: url, user: connection.user, password: "[REDACTED]" }
);
}
let authorization = connection.user + ":" + connection.password;
headers["authorization"] = {
key: "Authorization",
value: "Basic " + base64Encode(toUtf8Bytes(authorization))
};
}
}
return new Promise(function(resolve, reject) {
let timer: any = null;
if (timeout) {
timer = setTimeout(() => {
if (timer == null) { return; }
timer = null;
reject(logger.makeError("timeout", Logger.errors.TIMEOUT, { timeout: timeout }));
}, timeout);
}
if (connection.headers) {
for (var key in connection.headers) {
headers[key.toLowerCase()] = { key: key, value: String(connection.headers[key]) };
if (["if-none-match", "if-modified-since"].indexOf(key.toLowerCase()) >= 0) {
allow304 = true;
}
}
}
if (connection.user != null && connection.password != null) {
if (url.substring(0, 6) !== "https:" && connection.allowInsecureAuthentication !== true) {
logger.throwError("basic authentication requires a secure https url", logger_1.Logger.errors.INVALID_ARGUMENT, { argument: "url", url: url, user: connection.user, password: "[REDACTED]" });
}
var authorization = connection.user + ":" + connection.password;
headers["authorization"] = {
key: "Authorization",
value: "Basic " + base64_1.encode(strings_1.toUtf8Bytes(authorization))
};
}
}
if (json) {
options.method = "POST";
options.body = json;
headers["content-type"] = { key: "Content-Type", value: "application/json" };
}
var flatHeaders = {};
Object.keys(headers).forEach(function (key) {
var header = headers[key];
flatHeaders[header.key] = header.value;
});
options.headers = flatHeaders;
var runningTimeout = (function () {
var timer = null;
if (connection.headers) {
for (const key in connection.headers) {
headers[key.toLowerCase()] = { key: key, value: String(connection.headers[key]) };
if (["if-none-match", "if-modified-since"].indexOf(key.toLowerCase()) >= 0) {
allow304 = true;
}
}
}
if (connection.user != null && connection.password != null) {
if (url.substring(0, 6) !== "https:" && connection.allowInsecureAuthentication !== true) {
logger.throwError("basic authentication requires a secure https url", Logger.errors.INVALID_ARGUMENT, { argument: "url", url: url, user: connection.user, password: "[REDACTED]" });
}
const authorization = connection.user + ":" + connection.password;
headers["authorization"] = {
key: "Authorization",
value: "Basic " + base64Encode(toUtf8Bytes(authorization))
};
}
}
if (json) {
options.method = "POST";
options.body = json;
headers["content-type"] = { key: "Content-Type", value: "application/json" };
}
const flatHeaders = {};
Object.keys(headers).forEach((key) => {
const header = headers[key];
flatHeaders[header.key] = header.value;
});
options.headers = flatHeaders;
const runningTimeout = (function () {
let timer = null;