From cf62670d23386ef8278f4f6715f702956dbdf9f4 Mon Sep 17 00:00:00 2001 From: fuqiang05 Date: Sat, 6 May 2023 14:49:55 +0800 Subject: [PATCH] support node20 with fetch that must use duplex of requestInt --- package.json | 2 +- src/shared/http.ts | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 2ad441e..e1faf9d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@otakustay/bce-sdk", - "version": "0.12.8", + "version": "0.12.9", "description": "Yet another Baidu Cloud SDK", "type": "module", "exports": { diff --git a/src/shared/http.ts b/src/shared/http.ts index f8f25ed..e7fb750 100644 --- a/src/shared/http.ts +++ b/src/shared/http.ts @@ -149,13 +149,16 @@ export class Http { {timestamp} ); + const requestInit = { + method, + headers, + body: isPlainObject(options?.body) ? JSON.stringify(options?.body) : (options?.body ?? null), + duplex: 'half', + }; + const response = await fetch( this.baseUrl + url + (searchParams ? `?${searchParams}` : ''), - { - method, - headers, - body: isPlainObject(options?.body) ? JSON.stringify(options?.body) : (options?.body ?? null), - } + requestInit, ); const responseHeaders = entriesToRecord([...response.headers.entries()]);