Skip to content

Commit 8f4e945

Browse files
Merge pull request #12955 from josesilveiraa07/master
feat: Implement getHeader and appendHeader methods in adapters
2 parents a58f6a9 + 36411c3 commit 8f4e945

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

packages/core/adapters/http-adapter.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,11 @@ export abstract class AbstractHttpAdapter<
117117
abstract setErrorHandler(handler: Function, prefix?: string);
118118
abstract setNotFoundHandler(handler: Function, prefix?: string);
119119
abstract isHeadersSent(response: any);
120+
// TODO remove optional signature (v11)
121+
abstract getHeader?(response: any, name: string);
120122
abstract setHeader(response: any, name: string, value: string);
123+
// TODO remove optional signature (v11)
124+
abstract appendHeader?(response: any, name: string, value: string);
121125
abstract registerParserMiddleware(prefix?: string, rawBody?: boolean);
122126
abstract enableCors(
123127
options: CorsOptions | CorsOptionsDelegate<TRequest>,

packages/core/test/utils/noop-adapter.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ export class NoopHttpAdapter extends AbstractHttpAdapter {
2121
setErrorHandler(handler: Function, prefix = '/'): any {}
2222
setNotFoundHandler(handler: Function, prefix = '/'): any {}
2323
isHeadersSent(response: any): any {}
24+
getHeader?(response: any, name: string) {}
2425
setHeader(response: any, name: string, value: string): any {}
26+
appendHeader?(response: any, name: string, value: string) {}
2527
registerParserMiddleware(): any {}
2628
enableCors(options: any): any {}
2729
createMiddlewareFactory(requestMethod: RequestMethod): any {}

packages/platform-express/adapters/express-adapter.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,18 @@ export class ExpressAdapter extends AbstractHttpAdapter<
143143
return response.headersSent;
144144
}
145145

146+
public getHeader?(response: any, name: string) {
147+
return response.get(name);
148+
}
149+
146150
public setHeader(response: any, name: string, value: string) {
147151
return response.set(name, value);
148152
}
149153

154+
public appendHeader?(response: any, name: string, value: string) {
155+
return response.append(name, value);
156+
}
157+
150158
public listen(port: string | number, callback?: () => void): Server;
151159
public listen(
152160
port: string | number,

packages/platform-fastify/adapters/fastify-adapter.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,10 +466,18 @@ export class FastifyAdapter<
466466
return response.sent;
467467
}
468468

469+
public getHeader?(response: any, name: string) {
470+
return response.getHeader(name);
471+
}
472+
469473
public setHeader(response: TReply, name: string, value: string) {
470474
return response.header(name, value);
471475
}
472476

477+
public appendHeader?(response: any, name: string, value: string) {
478+
response.header(name, value);
479+
}
480+
473481
public getRequestHostname(request: TRequest): string {
474482
return request.hostname;
475483
}

0 commit comments

Comments
 (0)