Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implement getHeader and appendHeader methods in adapters #12955

Merged
merged 4 commits into from
Feb 7, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: Implement getHeader and appendHeader methods in adapters
The setHeader method would replace a header, while there can be multiple headers with the same name
josesilveiraa07 committed Dec 20, 2023
commit cfd0ab69a02f7094266830134c054b8a0ce4e723
4 changes: 4 additions & 0 deletions packages/core/adapters/http-adapter.ts
Original file line number Diff line number Diff line change
@@ -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>,
8 changes: 8 additions & 0 deletions packages/platform-express/adapters/express-adapter.ts
Original file line number Diff line number Diff line change
@@ -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,
8 changes: 8 additions & 0 deletions packages/platform-fastify/adapters/fastify-adapter.ts
Original file line number Diff line number Diff line change
@@ -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;
}