From 28ffe7e3dbb32de126e2ad475a69e1448eda5cc6 Mon Sep 17 00:00:00 2001 From: hbprotoss Date: Thu, 17 Apr 2025 21:10:58 +0800 Subject: [PATCH] fix: missing headers in some cases (#18283) Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: crazywoola <427733928@qq.com> --- web/service/fetch.ts | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/web/service/fetch.ts b/web/service/fetch.ts index fc41310c8..5d09256f1 100644 --- a/web/service/fetch.ts +++ b/web/service/fetch.ts @@ -132,12 +132,13 @@ async function base(url: string, options: FetchOptionType = {}, otherOptions: getAbortController, } = otherOptions - const base - = isMarketplaceAPI - ? MARKETPLACE_API_PREFIX - : isPublicAPI - ? PUBLIC_API_PREFIX - : API_PREFIX + let base: string + if (isMarketplaceAPI) + base = MARKETPLACE_API_PREFIX + else if (isPublicAPI) + base = PUBLIC_API_PREFIX + else + base = API_PREFIX if (getAbortController) { const abortController = new AbortController() @@ -145,7 +146,7 @@ async function base(url: string, options: FetchOptionType = {}, otherOptions: options.signal = abortController.signal } - const fetchPathname = `${base}${url.startsWith('/') ? url : `/${url}`}` + const fetchPathname = base + (url.startsWith('/') ? url : `/${url}`) if (deleteContentType) (headers as any).delete('Content-Type') @@ -180,6 +181,16 @@ async function base(url: string, options: FetchOptionType = {}, otherOptions: }, ...(bodyStringify ? { json: body } : { body: body as BodyInit }), searchParams: params, + fetch(resource: RequestInfo | URL, options?: RequestInit) { + if (resource instanceof Request && options) { + const mergedHeaders = new Headers(options.headers || {}) + resource.headers.forEach((value, key) => { + mergedHeaders.append(key, value) + }) + options.headers = mergedHeaders + } + return globalThis.fetch(resource, options) + }, }) if (needAllResponseContent)