summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-webextension/src/browserHttpLib.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2020-12-02 14:55:04 +0100
committerFlorian Dold <florian@dold.me>2020-12-02 14:55:04 +0100
commit89f1a281fea66b986fc0a003dc10446f6ed6e4a2 (patch)
tree8ffe90d572bc6967ee86bdcffc1eb6dc1240d17c /packages/taler-wallet-webextension/src/browserHttpLib.ts
parent0828e65f8845dc4b148c0d3b0697fb589b338239 (diff)
downloadwallet-core-89f1a281fea66b986fc0a003dc10446f6ed6e4a2.tar.gz
wallet-core-89f1a281fea66b986fc0a003dc10446f6ed6e4a2.tar.bz2
wallet-core-89f1a281fea66b986fc0a003dc10446f6ed6e4a2.zip
backup WIP
Diffstat (limited to 'packages/taler-wallet-webextension/src/browserHttpLib.ts')
-rw-r--r--packages/taler-wallet-webextension/src/browserHttpLib.ts25
1 files changed, 15 insertions, 10 deletions
diff --git a/packages/taler-wallet-webextension/src/browserHttpLib.ts b/packages/taler-wallet-webextension/src/browserHttpLib.ts
index 96484bc97..bfc855633 100644
--- a/packages/taler-wallet-webextension/src/browserHttpLib.ts
+++ b/packages/taler-wallet-webextension/src/browserHttpLib.ts
@@ -34,12 +34,9 @@ const logger = new Logger("browserHttpLib");
* browser's XMLHttpRequest.
*/
export class BrowserHttpLib implements HttpRequestLibrary {
- private req(
- method: string,
- url: string,
- requestBody?: any,
- options?: HttpRequestOptions,
- ): Promise<HttpResponse> {
+ fetch(url: string, options?: HttpRequestOptions): Promise<HttpResponse> {
+ const method = options?.method ?? "GET";
+ let requestBody = options?.body;
return new Promise<HttpResponse>((resolve, reject) => {
const myRequest = new XMLHttpRequest();
myRequest.open(method, url);
@@ -48,7 +45,7 @@ export class BrowserHttpLib implements HttpRequestLibrary {
myRequest.setRequestHeader(headerName, options.headers[headerName]);
}
}
- myRequest.setRequestHeader;
+ myRequest.responseType = "arraybuffer";
if (requestBody) {
myRequest.send(requestBody);
} else {
@@ -130,6 +127,7 @@ export class BrowserHttpLib implements HttpRequestLibrary {
requestMethod: method,
json: makeJson,
text: async () => myRequest.responseText,
+ bytes: async () => myRequest.response,
};
resolve(resp);
}
@@ -138,15 +136,22 @@ export class BrowserHttpLib implements HttpRequestLibrary {
}
get(url: string, opt?: HttpRequestOptions): Promise<HttpResponse> {
- return this.req("GET", url, undefined, opt);
+ return this.fetch(url, {
+ method: "GET",
+ ...opt,
+ });
}
postJson(
url: string,
- body: unknown,
+ body: any,
opt?: HttpRequestOptions,
): Promise<HttpResponse> {
- return this.req("POST", url, JSON.stringify(body), opt);
+ return this.fetch(url, {
+ method: "POST",
+ body,
+ ...opt,
+ });
}
stop(): void {