Files
handlers.js/src/interface/headers.ts
2024-07-19 12:38:11 +08:00

32 lines
962 B
TypeScript

import * as lib from '../lib';
export class headers {
public headers: { [key: string]: string } = {};
constructor(headers: { [key: string]: string }) {
this.headers = {};
Object.keys(headers).forEach((key) => {
this.headers[lib.firstUpperCase(key)] = headers[key];
});
}
delete(key: string) {
delete this.headers[lib.firstUpperCase(key)];
}
get(key: string): string | undefined {
return this.headers[lib.firstUpperCase(key)];
}
has(key: string): boolean {
return this.headers.hasOwnProperty(lib.firstUpperCase(key));
}
set(key: string, value: string) {
this.headers[lib.firstUpperCase(key)] = value;
}
toObject() {
return this.headers;
}
forEach(func: (key: string, value: string) => any) {
Object.keys(this.headers).forEach((key) => {
func(key, this.headers[key]);
});
}
}
export default headers;