mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-22 13:28:10 +00:00
31 lines
926 B
TypeScript
31 lines
926 B
TypeScript
// Google plugin module implements oauth.http behavior.
|
|
import {
|
|
shouldUseEnvHttpProxyForUrl,
|
|
withTrustedEnvProxyGuardedFetchMode,
|
|
} from "openclaw/plugin-sdk/fetch-runtime";
|
|
import { fetchWithSsrFGuard } from "openclaw/plugin-sdk/ssrf-runtime";
|
|
import { DEFAULT_FETCH_TIMEOUT_MS } from "./oauth.shared.js";
|
|
|
|
export async function fetchWithTimeout(
|
|
url: string,
|
|
init: RequestInit,
|
|
timeoutMs = DEFAULT_FETCH_TIMEOUT_MS,
|
|
): Promise<Response> {
|
|
const guardedOptions = { url, init, timeoutMs };
|
|
const { response, release } = await fetchWithSsrFGuard(
|
|
shouldUseEnvHttpProxyForUrl(url)
|
|
? withTrustedEnvProxyGuardedFetchMode(guardedOptions)
|
|
: guardedOptions,
|
|
);
|
|
try {
|
|
const body = await response.arrayBuffer();
|
|
return new Response(body, {
|
|
status: response.status,
|
|
statusText: response.statusText,
|
|
headers: response.headers,
|
|
});
|
|
} finally {
|
|
await release();
|
|
}
|
|
}
|