|
@@ -103,9 +103,10 @@ export class ResponsePolyfill {
|
|
|
if (!headers.has('Content-Type')) {
|
|
if (!headers.has('Content-Type')) {
|
|
|
headers.set('Content-Type', 'application/json')
|
|
headers.set('Content-Type', 'application/json')
|
|
|
}
|
|
}
|
|
|
- // @ts-expect-error - Headers.raw() 是非标准 API,但在小程序环境中需要使用
|
|
|
|
|
- const headersRecord = typeof (headers as { raw?: () => Record<string, string> }).raw === 'function'
|
|
|
|
|
- ? (headers as { raw: () => Record<string, string> }).raw()
|
|
|
|
|
|
|
+ // Headers.raw() 是非标准 API,某些实现(如 node-fetch)提供此方法
|
|
|
|
|
+ const headersWithRaw = headers as { raw?: () => Record<string, string> }
|
|
|
|
|
+ const headersRecord = typeof headersWithRaw.raw === 'function'
|
|
|
|
|
+ ? headersWithRaw.raw()
|
|
|
: {}
|
|
: {}
|
|
|
return new ResponsePolyfill(JSON.stringify(data), {
|
|
return new ResponsePolyfill(JSON.stringify(data), {
|
|
|
...init,
|
|
...init,
|
|
@@ -131,4 +132,4 @@ export function registerGlobalResponsePolyfill(): void {
|
|
|
// @ts-expect-error - 全局类型赋值
|
|
// @ts-expect-error - 全局类型赋值
|
|
|
globalThis.Response = ResponsePolyfill
|
|
globalThis.Response = ResponsePolyfill
|
|
|
}
|
|
}
|
|
|
-}
|
|
|
|
|
|
|
+}
|