mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-06-04 11:14:10 +08:00
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>
This commit is contained in:
parent
721294948c
commit
28ffe7e3db
@ -132,12 +132,13 @@ async function base<T>(url: string, options: FetchOptionType = {}, otherOptions:
|
|||||||
getAbortController,
|
getAbortController,
|
||||||
} = otherOptions
|
} = otherOptions
|
||||||
|
|
||||||
const base
|
let base: string
|
||||||
= isMarketplaceAPI
|
if (isMarketplaceAPI)
|
||||||
? MARKETPLACE_API_PREFIX
|
base = MARKETPLACE_API_PREFIX
|
||||||
: isPublicAPI
|
else if (isPublicAPI)
|
||||||
? PUBLIC_API_PREFIX
|
base = PUBLIC_API_PREFIX
|
||||||
: API_PREFIX
|
else
|
||||||
|
base = API_PREFIX
|
||||||
|
|
||||||
if (getAbortController) {
|
if (getAbortController) {
|
||||||
const abortController = new AbortController()
|
const abortController = new AbortController()
|
||||||
@ -145,7 +146,7 @@ async function base<T>(url: string, options: FetchOptionType = {}, otherOptions:
|
|||||||
options.signal = abortController.signal
|
options.signal = abortController.signal
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchPathname = `${base}${url.startsWith('/') ? url : `/${url}`}`
|
const fetchPathname = base + (url.startsWith('/') ? url : `/${url}`)
|
||||||
|
|
||||||
if (deleteContentType)
|
if (deleteContentType)
|
||||||
(headers as any).delete('Content-Type')
|
(headers as any).delete('Content-Type')
|
||||||
@ -180,6 +181,16 @@ async function base<T>(url: string, options: FetchOptionType = {}, otherOptions:
|
|||||||
},
|
},
|
||||||
...(bodyStringify ? { json: body } : { body: body as BodyInit }),
|
...(bodyStringify ? { json: body } : { body: body as BodyInit }),
|
||||||
searchParams: params,
|
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)
|
if (needAllResponseContent)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user