diff options
author | Florian Dold <florian.dold@gmail.com> | 2019-12-09 13:29:11 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2019-12-09 13:29:11 +0100 |
commit | 1fea75bca3951d39c0a45faf3e903fcec77f9c4f (patch) | |
tree | 8d582e26a7e583871e0c9c223976e67b93ef2059 /src/android/index.ts | |
parent | 396bb61db70f654599256e512bfec4c008ee8269 (diff) | |
download | wallet-core-1fea75bca3951d39c0a45faf3e903fcec77f9c4f.tar.xz |
throttling / allow non-json requests
Diffstat (limited to 'src/android/index.ts')
-rw-r--r-- | src/android/index.ts | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/android/index.ts b/src/android/index.ts index 300cffd12..ec5853543 100644 --- a/src/android/index.ts +++ b/src/android/index.ts @@ -26,7 +26,7 @@ import { } from "../headless/helpers"; import { openPromise, OpenedPromise } from "../util/promiseUtils"; import fs = require("fs"); -import { HttpRequestLibrary, HttpResponse } from "../util/http"; +import { HttpRequestLibrary, HttpResponse, HttpRequestOptions } from "../util/http"; // @ts-ignore: special built-in module //import akono = require("akono"); @@ -44,7 +44,7 @@ export class AndroidHttpLib implements HttpRequestLibrary { constructor(private sendMessage: (m: string) => void) {} - get(url: string): Promise<HttpResponse> { + get(url: string, opt?: HttpRequestOptions): Promise<HttpResponse> { if (this.useNfcTunnel) { const myId = this.requestId++; const p = openPromise<HttpResponse>(); @@ -62,11 +62,11 @@ export class AndroidHttpLib implements HttpRequestLibrary { ); return p.promise; } else { - return this.nodeHttpLib.get(url); + return this.nodeHttpLib.get(url, opt); } } - postJson(url: string, body: any): Promise<import("../util/http").HttpResponse> { + postJson(url: string, body: any, opt?: HttpRequestOptions): Promise<import("../util/http").HttpResponse> { if (this.useNfcTunnel) { const myId = this.requestId++; const p = openPromise<HttpResponse>(); @@ -81,7 +81,7 @@ export class AndroidHttpLib implements HttpRequestLibrary { ); return p.promise; } else { - return this.nodeHttpLib.postJson(url, body); + return this.nodeHttpLib.postJson(url, body, opt); } } @@ -91,8 +91,14 @@ export class AndroidHttpLib implements HttpRequestLibrary { if (!p) { console.error(`no matching request for tunneled HTTP response, id=${myId}`); } - if (msg.status == 200) { - p.resolve({ responseJson: msg.responseJson, status: msg.status }); + if (msg.status != 0) { + const resp: HttpResponse = { + headers: {}, + status: msg.status, + json: async () => JSON.parse(msg.responseText), + text: async () => msg.responseText, + }; + p.resolve(resp); } else { p.reject(new Error(`unexpected HTTP status code ${msg.status}`)); } |