mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
21 lines
575 B
TypeScript
21 lines
575 B
TypeScript
import { HttpHandler } from '../HttpHandler';
|
|
import type { HttpResponse } from '../HttpResponse';
|
|
|
|
/**
|
|
* Handler that sets custom headers on the response.
|
|
*/
|
|
export class HeaderHandler extends HttpHandler {
|
|
private readonly headers: Record<string, string>;
|
|
|
|
public constructor(headers: Record<string, string>) {
|
|
super();
|
|
this.headers = { ...headers };
|
|
}
|
|
|
|
public async handle({ response }: { response: HttpResponse }): Promise<void> {
|
|
for (const header of Object.keys(this.headers)) {
|
|
response.setHeader(header, this.headers[header]);
|
|
}
|
|
}
|
|
}
|