mirror of
https://github.com/denoland/deno.git
synced 2024-12-25 00:29:09 -05:00
fb0b99408b
Original: 36edda18ab
34 lines
785 B
TypeScript
34 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]();
|
|
}
|
|
}
|