feat(http): add proxy support (#4721)

This commit is contained in:
Meier Lukas
2025-12-25 11:32:14 +01:00
committed by GitHub
parent 707a4dad83
commit 5a57115ca0
10 changed files with 52 additions and 30 deletions

View File

@@ -1,5 +1,5 @@
import type { Dispatcher } from "undici";
import { Agent } from "undici";
import { EnvHttpProxyAgent } from "undici";
import type { ILogger } from "@homarr/core/infrastructure/logs";
import { createLogger } from "@homarr/core/infrastructure/logs";
@@ -7,16 +7,15 @@ import { createLogger } from "@homarr/core/infrastructure/logs";
// The below import statement initializes dns-caching
import "@homarr/core/infrastructure/dns/init";
interface HttpAgentOptions extends Agent.Options {
interface HttpAgentOptions extends EnvHttpProxyAgent.Options {
logger?: ILogger;
}
export class UndiciHttpAgent extends Agent {
export class UndiciHttpAgent extends EnvHttpProxyAgent {
private logger: ILogger;
constructor(props?: HttpAgentOptions) {
super(props);
this.logger = props?.logger ?? createLogger({ module: "httpAgent" });
}

View File

@@ -42,12 +42,13 @@ export const createCertificateAgentAsync = async (override?: {
};
export const createHttpsAgentAsync = async (override?: Pick<AgentOptions, "ca" | "checkServerIdentity">) => {
return new HttpsAgent(
override ?? {
ca: await getAllTrustedCertificatesAsync(),
checkServerIdentity: createCustomCheckServerIdentity(await getTrustedCertificateHostnamesAsync()),
},
);
return new HttpsAgent({
ca: await getAllTrustedCertificatesAsync(),
checkServerIdentity: createCustomCheckServerIdentity(await getTrustedCertificateHostnamesAsync()),
// Override the ca and checkServerIdentity if provided
...override,
proxyEnv: process.env,
});
};
export const createAxiosCertificateInstanceAsync = async (

View File

@@ -7,7 +7,7 @@ import { TestLogger } from "../logs";
vi.mock("undici", () => {
return {
Agent: class Agent {
EnvHttpProxyAgent: class EnvHttpProxyAgent {
dispatch(_options: Dispatcher.DispatchOptions, _handler: Dispatcher.DispatchHandler): boolean {
return true;
}