mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-08 14:38:47 +00:00
Better login strategy for qbittorrent proxy
- Additional logging in httpProxy
This commit is contained in:
parent
1ea8e38372
commit
65755a08aa
2 changed files with 42 additions and 14 deletions
|
@ -4,6 +4,10 @@ import { http, https } from "follow-redirects";
|
|||
|
||||
import { addCookieToJar, setCookieHeader } from "./cookie-jar";
|
||||
|
||||
import createLogger from "utils/logger";
|
||||
|
||||
const logger = createLogger("httpProxy");
|
||||
|
||||
function addCookieHandler(url, params) {
|
||||
setCookieHeader(url, params);
|
||||
|
||||
|
@ -70,18 +74,30 @@ export function httpRequest(url, params) {
|
|||
});
|
||||
}
|
||||
|
||||
export function httpProxy(url, params = {}) {
|
||||
export async function httpProxy(url, params = {}) {
|
||||
const constructedUrl = new URL(url);
|
||||
|
||||
let request = null;
|
||||
if (constructedUrl.protocol === "https:") {
|
||||
const httpsAgent = new https.Agent({
|
||||
rejectUnauthorized: false,
|
||||
});
|
||||
|
||||
return httpsRequest(constructedUrl, {
|
||||
request = httpsRequest(constructedUrl, {
|
||||
agent: httpsAgent,
|
||||
...params,
|
||||
});
|
||||
} else {
|
||||
request = httpRequest(constructedUrl, params);
|
||||
}
|
||||
|
||||
try {
|
||||
const [status, contentType, data, responseHeaders] = await request;
|
||||
return [status, contentType, data, responseHeaders];
|
||||
}
|
||||
catch (err) {
|
||||
logger.error("Error calling %s//%s%s...", url.protocol, url.hostname, url.pathname);
|
||||
logger.error(err);
|
||||
return [500, "application/json", { error: "Unexpected error" }, null];
|
||||
}
|
||||
return httpRequest(constructedUrl, params);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue