


























@@ -406,6 +406,30 @@ function createGatewayPlugin(params: {
406406return new SafeGatewayPlugin();
407407}
408408409+async function fetchDiscordGatewayMetadataDirect(
410+input: string,
411+init?: DiscordGatewayFetchInit,
412+capture?: false | { flowId: string; meta: Record<string, unknown> },
413+): Promise<Response> {
414+const runtimeFetch = globalThis.fetch;
415+if (typeof runtimeFetch !== "function") {
416+throw new Error("fetch is not available");
417+}
418+const response = await runtimeFetch(input, init as RequestInit);
419+if (capture) {
420+captureHttpExchange({
421+url: input,
422+method: (init?.method as string | undefined) ?? "GET",
423+requestHeaders: init?.headers as Headers | Record<string, string> | undefined,
424+requestBody: (init as RequestInit & { body?: BodyInit | null })?.body ?? null,
425+ response,
426+flowId: capture.flowId,
427+meta: capture.meta,
428+});
429+}
430+return response;
431+}
432+409433export function waitForDiscordGatewayPluginRegistration(
410434plugin: unknown,
411435): Promise<void> | undefined {
@@ -442,19 +466,16 @@ export function createDiscordGatewayPlugin(params: {
442466return createGatewayPlugin({
443467 options,
444468fetchImpl: async (input, init) => {
445-const response = await fetch(input, init as RequestInit);
446-if (!debugProxySettings.enabled) {
447-captureHttpExchange({
448-url: input,
449-method: (init?.method as string | undefined) ?? "GET",
450-requestHeaders: init?.headers as Headers | Record<string, string> | undefined,
451-requestBody: (init as RequestInit & { body?: BodyInit | null })?.body ?? null,
452- response,
453-flowId: randomUUID(),
454-meta: { subsystem: "discord-gateway-metadata" },
455-});
456-}
457-return response;
469+return await fetchDiscordGatewayMetadataDirect(
470+input,
471+init,
472+debugProxySettings.enabled
473+ ? false
474+ : {
475+flowId: randomUUID(),
476+meta: { subsystem: "discord-gateway-metadata" },
477+},
478+);
458479},
459480runtime: params.runtime,
460481testing: params.__testing
@@ -508,7 +529,7 @@ export function createDiscordGatewayPlugin(params: {
508529params.runtime.error?.(danger(`discord: invalid gateway proxy: ${String(err)}`));
509530return createGatewayPlugin({
510531 options,
511-fetchImpl: (input, init) => fetch(input, init as RequestInit),
532+fetchImpl: (input, init) => fetchDiscordGatewayMetadataDirect(input, init, false),
512533runtime: params.runtime,
513534testing: params.__testing
514535 ? {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。