summaryrefslogtreecommitdiff
path: root/headers.ts
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2018-11-08 12:58:43 -0500
committerRyan Dahl <ry@tinyclouds.org>2018-11-08 12:58:43 -0500
commitfb0b99408b1ce0c8061d654e9dae3fd8221efa6f (patch)
tree82a3edc234b67ea9f9c8e8f75176a9700dc7504e /headers.ts
parent0c324a442ef4a296bd925972dfbe3fc94c60b256 (diff)
Add tests for TextProtoReader.readMIMEHeader()
Original: https://github.com/denoland/deno_std/commit/36edda18ab75ea8287088478d46e89e5e8d6be0f
Diffstat (limited to 'headers.ts')
-rw-r--r--headers.ts34
1 files changed, 34 insertions, 0 deletions
diff --git a/headers.ts b/headers.ts
new file mode 100644
index 000000000..9fe218195
--- /dev/null
+++ b/headers.ts
@@ -0,0 +1,34 @@
+// Fake headers to work around
+// https://github.com/denoland/deno/issues/1173
+
+function normalize(name: string, value?: string): [string, string] {
+ name = String(name).toLowerCase();
+ value = String(value).trim();
+ return [name, value];
+}
+
+export class Headers {
+ private map = new Map<string, string>();
+
+ get(name: string): string | null {
+ let [name_] = normalize(name);
+ return this.map.get(name_);
+ }
+
+ append(name: string, value: string): void {
+ [name, value] = normalize(name, value);
+ this.map.set(name, value);
+ }
+
+ toString(): string {
+ let out = "";
+ this.map.forEach((v, k) => {
+ out += `${k}: ${v}\n`;
+ });
+ return out;
+ }
+
+ [Symbol.iterator](): IterableIterator<[string, string]> {
+ return this.map[Symbol.iterator]();
+ }
+}