






























@@ -20,6 +20,9 @@ type GoogleAuthRuntime = {
2020OAuth2Client: GoogleAuthModule["OAuth2Client"];
2121};
2222type GoogleAuthTransport = InstanceType<GaxiosModule["Gaxios"]>;
23+type GoogleAuthRequestWithUnknownHeaders = RequestInit & {
24+headers?: unknown;
25+};
2326type GuardedGoogleAuthRequestInit = RequestInit & {
2427agent?: unknown;
2528cert?: unknown;
@@ -67,6 +70,24 @@ const MAX_GOOGLE_CHAT_SERVICE_ACCOUNT_FILE_BYTES = 64 * 1024;
6770let googleAuthRuntimePromise: Promise<GoogleAuthRuntime> | null = null;
6871let googleAuthTransportPromise: Promise<GoogleAuthTransport> | null = null;
697273+function normalizeGoogleAuthPreparedRequestHeaders<T extends GoogleAuthRequestWithUnknownHeaders>(
74+config: T,
75+): T & { headers: Headers } {
76+if (!(config.headers instanceof Headers)) {
77+config.headers = new Headers(config.headers as HeadersInit | undefined);
78+}
79+return config as T & { headers: Headers };
80+}
81+82+function installGoogleAuthHeaderCompatibilityInterceptor(
83+transport: GoogleAuthTransport,
84+): GoogleAuthTransport {
85+transport.interceptors.request.add({
86+resolved: async (config) => normalizeGoogleAuthPreparedRequestHeaders(config),
87+});
88+return transport;
89+}
90+7091function asNullableObjectRecord(value: unknown): Record<string, unknown> | null {
7192return value !== null && typeof value === "object" ? (value as Record<string, unknown>) : null;
7293}
@@ -504,9 +525,11 @@ export async function getGoogleAuthTransport(): Promise<GoogleAuthTransport> {
504525googleAuthTransportPromise = (async () => {
505526try {
506527const { Gaxios } = await loadGoogleAuthRuntime();
507-return new Gaxios({
508-fetchImplementation: createGoogleAuthFetch(),
509-});
528+return installGoogleAuthHeaderCompatibilityInterceptor(
529+new Gaxios({
530+fetchImplementation: createGoogleAuthFetch(),
531+}),
532+);
510533} catch (error) {
511534googleAuthTransportPromise = null;
512535throw error;
@@ -534,6 +557,7 @@ export const __testing = {
534557googleAuthRuntimePromise = null;
535558googleAuthTransportPromise = null;
536559},
560+ normalizeGoogleAuthPreparedRequestHeaders,
537561 resolveGoogleAuthEnvProxyUrl,
538562 validateGoogleChatServiceAccountCredentials,
539563};
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。