diff options
author | Florian Dold <florian@dold.me> | 2022-11-12 19:18:55 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2022-11-12 19:18:55 +0100 |
commit | f09a502fe7f1cb7583265c91ff95bbb4740720b0 (patch) | |
tree | 3e89028729621ca34731160de7db19b86f4a26e0 /packages/taler-wallet-webextension/src | |
parent | 233a354b4728b5efc76d19a530ad85a3a3e2a3d2 (diff) | |
download | wallet-core-f09a502fe7f1cb7583265c91ff95bbb4740720b0.tar.xz |
fix URLSearchParams and HTTP typing issue
Diffstat (limited to 'packages/taler-wallet-webextension/src')
-rw-r--r-- | packages/taler-wallet-webextension/src/browserHttpLib.ts | 11 | ||||
-rw-r--r-- | packages/taler-wallet-webextension/src/serviceWorkerHttpLib.ts | 17 |
2 files changed, 26 insertions, 2 deletions
diff --git a/packages/taler-wallet-webextension/src/browserHttpLib.ts b/packages/taler-wallet-webextension/src/browserHttpLib.ts index d318e8201..26fa8eb11 100644 --- a/packages/taler-wallet-webextension/src/browserHttpLib.ts +++ b/packages/taler-wallet-webextension/src/browserHttpLib.ts @@ -27,6 +27,7 @@ import { import { Logger, RequestThrottler, + stringToBytes, TalerErrorCode, } from "@gnu-taler/taler-util"; @@ -70,7 +71,15 @@ export class BrowserHttpLib implements HttpRequestLibrary { } myRequest.responseType = "arraybuffer"; if (requestBody) { - myRequest.send(requestBody); + if (requestBody instanceof ArrayBuffer) { + myRequest.send(requestBody); + } else if (ArrayBuffer.isView(requestBody)) { + myRequest.send(requestBody); + } else if (typeof requestBody === "string") { + myRequest.send(requestBody); + } else { + myRequest.send(JSON.stringify(requestBody)); + } } else { myRequest.send(); } diff --git a/packages/taler-wallet-webextension/src/serviceWorkerHttpLib.ts b/packages/taler-wallet-webextension/src/serviceWorkerHttpLib.ts index b9648ced8..74c7f161d 100644 --- a/packages/taler-wallet-webextension/src/serviceWorkerHttpLib.ts +++ b/packages/taler-wallet-webextension/src/serviceWorkerHttpLib.ts @@ -55,9 +55,24 @@ export class ServiceWorkerHttpLib implements HttpRequestLibrary { ); } + let myBody: BodyInit | undefined = undefined; + if (requestBody != null) { + if (typeof requestBody === "string") { + myBody = requestBody; + } else if (requestBody instanceof ArrayBuffer) { + myBody = requestBody; + } else if (ArrayBuffer.isView(requestBody)) { + myBody = requestBody; + } else if (typeof requestBody === "object") { + myBody = JSON.stringify(myBody); + } else { + throw Error("unsupported request body type"); + } + } + const response = await fetch(requestUrl, { headers: requestHeader, - body: requestBody, + body: myBody, method: requestMethod, // timeout: options?.timeout }); |