summaryrefslogtreecommitdiff
path: root/src/util/http.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2019-12-09 19:59:08 +0100
committerFlorian Dold <florian.dold@gmail.com>2019-12-09 19:59:08 +0100
commit6415564b9259a4a6a2f6ec9cb934eab3d56a1677 (patch)
tree577372a635b5503c1ad81b2af8523a839e790bb7 /src/util/http.ts
parent99bccae9fe1588f711e7606dc3c6d7dd4a25675a (diff)
downloadwallet-core-6415564b9259a4a6a2f6ec9cb934eab3d56a1677.tar.gz
wallet-core-6415564b9259a4a6a2f6ec9cb934eab3d56a1677.tar.bz2
wallet-core-6415564b9259a4a6a2f6ec9cb934eab3d56a1677.zip
tos
Diffstat (limited to 'src/util/http.ts')
-rw-r--r--src/util/http.ts31
1 files changed, 28 insertions, 3 deletions
diff --git a/src/util/http.ts b/src/util/http.ts
index ab253b232..79039f516 100644
--- a/src/util/http.ts
+++ b/src/util/http.ts
@@ -24,7 +24,7 @@
*/
export interface HttpResponse {
status: number;
- headers: { [name: string]: string };
+ headers: Headers;
json(): Promise<any>;
text(): Promise<string>;
}
@@ -34,6 +34,31 @@ export interface HttpRequestOptions {
}
/**
+ * Headers, roughly modeled after the fetch API's headers object.
+ */
+export class Headers {
+ private headerMap = new Map<string, string>();
+
+ get(name: string): string | null {
+ const r = this.headerMap.get(name.toLowerCase());
+ if (r) {
+ return r;
+ }
+ return null;
+ }
+
+ set(name: string, value: string): void {
+ const normalizedName = name.toLowerCase();
+ const existing = this.headerMap.get(normalizedName);
+ if (existing !== undefined) {
+ this.headerMap.set(normalizedName, existing + "," + value);
+ } else {
+ this.headerMap.set(normalizedName, value);
+ }
+ }
+}
+
+/**
* The request library is bundled into an interface to m responseJson: object & any;ake mocking easy.
*/
export interface HttpRequestLibrary {
@@ -103,12 +128,12 @@ export class BrowserHttpLib implements HttpRequestLibrary {
const arr = headers.trim().split(/[\r\n]+/);
// Create a map of header names to values
- const headerMap: { [name: string]: string } = {};
+ const headerMap = new Headers();
arr.forEach(function(line) {
const parts = line.split(": ");
const header = parts.shift();
const value = parts.join(": ");
- headerMap[header!] = value;
+ headerMap.set(header!, value);
});
const resp: HttpResponse = {
status: myRequest.status,