Skip to content

Commit

Permalink
feat: Implement getHeader and appendHeader methods in adapters
Browse files Browse the repository at this point in the history
The setHeader method would replace a header, while there can be multiple headers with the same name
  • Loading branch information
josesilveiraa07 committed Dec 20, 2023
1 parent 18335ff commit cfd0ab6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/core/adapters/http-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ export abstract class AbstractHttpAdapter<
abstract setErrorHandler(handler: Function, prefix?: string);
abstract setNotFoundHandler(handler: Function, prefix?: string);
abstract isHeadersSent(response: any);
// TODO remove optional signature (v11)
abstract getHeader?(response: any, name: string, value: string);
abstract setHeader(response: any, name: string, value: string);
// TODO remove optional signature (v11)
abstract appendHeader?(response: any, name: string, value: string);
abstract registerParserMiddleware(prefix?: string, rawBody?: boolean);
abstract enableCors(
options: CorsOptions | CorsOptionsDelegate<TRequest>,
Expand Down
8 changes: 8 additions & 0 deletions packages/platform-express/adapters/express-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,18 @@ export class ExpressAdapter extends AbstractHttpAdapter<
return response.headersSent;
}

public getHeader?(response: any, name: string) {
return response.get(name);
}

public setHeader(response: any, name: string, value: string) {
return response.set(name, value);
}

public appendHeader?(response: any, name: string, value: string) {
return response.append(name, value);
}

public listen(port: string | number, callback?: () => void): Server;
public listen(
port: string | number,
Expand Down
8 changes: 8 additions & 0 deletions packages/platform-fastify/adapters/fastify-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,10 +466,18 @@ export class FastifyAdapter<
return response.sent;
}

public getHeader?(response: any, name: string, value: string) {
return response.getHeader(name, value);
}

public setHeader(response: TReply, name: string, value: string) {
return response.header(name, value);
}

public appendHeader?(response: any, name: string, value: string) {
response.header(name, value);
}

public getRequestHostname(request: TRequest): string {
return request.hostname;
}
Expand Down

0 comments on commit cfd0ab6

Please sign in to comment.