mirror of
https://github.com/denoland/deno.git
synced 2025-01-19 04:16:00 -05:00
35 lines
785 B
TypeScript
35 lines
785 B
TypeScript
|
// 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]();
|
||
|
}
|
||
|
}
|