mirror of
https://github.com/186526/handlers.js
synced 2024-10-13 00:29:43 +00:00
32 lines
962 B
TypeScript
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;
|