mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-19 21:52:21 +03:00
test relay routing fallback headers (#5526)
Integrated into release/v3.8.42 (round 3). Relay fallback header extraction + tests (drift-shed: dependabot #5415 commit dropped).
This commit is contained in:
@@ -20,6 +20,7 @@ import {
|
||||
} from "./relaySecurity";
|
||||
import {
|
||||
getBifrostRoutingConfig,
|
||||
getRoutingFallbackHeader,
|
||||
resolveRelayRoutingBackend,
|
||||
shouldTryBifrost,
|
||||
type BifrostRoutingConfig,
|
||||
@@ -335,8 +336,9 @@ export async function POST(request: Request) {
|
||||
const newHeaders = new Headers(response.headers);
|
||||
newHeaders.set("X-Relay-Token", token.tokenPrefix + "...");
|
||||
newHeaders.set("X-Routing-Backend", "ts");
|
||||
if (backend === "auto" && bifrostConfig?.enabled) {
|
||||
newHeaders.set("X-Routing-Fallback", "bifrost");
|
||||
const routingFallback = getRoutingFallbackHeader(backend, bifrostConfig);
|
||||
if (routingFallback) {
|
||||
newHeaders.set("X-Routing-Fallback", routingFallback);
|
||||
}
|
||||
|
||||
return new Response(response.body, {
|
||||
|
||||
@@ -10,7 +10,9 @@ export interface BifrostRoutingConfig {
|
||||
enabled: boolean;
|
||||
}
|
||||
|
||||
export function getBifrostRoutingConfig(env: NodeJS.ProcessEnv = process.env): BifrostRoutingConfig | null {
|
||||
export function getBifrostRoutingConfig(
|
||||
env: NodeJS.ProcessEnv = process.env
|
||||
): BifrostRoutingConfig | null {
|
||||
const baseUrl = env.BIFROST_BASE_URL?.replace(/\/$/, "");
|
||||
if (!baseUrl) return null;
|
||||
const timeoutMs = Number.parseInt(env.BIFROST_TIMEOUT_MS || "", 10);
|
||||
@@ -24,7 +26,9 @@ export function getBifrostRoutingConfig(env: NodeJS.ProcessEnv = process.env): B
|
||||
};
|
||||
}
|
||||
|
||||
export function resolveRelayRoutingBackend(env: NodeJS.ProcessEnv = process.env): RelayRoutingBackend {
|
||||
export function resolveRelayRoutingBackend(
|
||||
env: NodeJS.ProcessEnv = process.env
|
||||
): RelayRoutingBackend {
|
||||
const configured = env.OMNIROUTE_RELAY_BACKEND || env.RELAY_ROUTING_BACKEND;
|
||||
if (configured && VALID_BACKENDS.has(configured as RelayRoutingBackend)) {
|
||||
return configured as RelayRoutingBackend;
|
||||
@@ -39,3 +43,10 @@ export function shouldTryBifrost(
|
||||
): config is BifrostRoutingConfig {
|
||||
return Boolean(config?.enabled && backend !== "ts");
|
||||
}
|
||||
|
||||
export function getRoutingFallbackHeader(
|
||||
backend: RelayRoutingBackend,
|
||||
config: BifrostRoutingConfig | null
|
||||
): "bifrost" | undefined {
|
||||
return backend === "auto" && config?.enabled ? "bifrost" : undefined;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user