Skip to content

Commit

Permalink
Merge pull request #12955 from josesilveiraa07/master
Browse files Browse the repository at this point in the history
feat: Implement getHeader and appendHeader methods in adapters
  • Loading branch information
kamilmysliwiec committed Feb 7, 2024
2 parents a58f6a9 + 36411c3 commit 8f4e945
Show file tree
Hide file tree
Showing 4 changed files with 22 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);
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
2 changes: 2 additions & 0 deletions packages/core/test/utils/noop-adapter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ export class NoopHttpAdapter extends AbstractHttpAdapter {
setErrorHandler(handler: Function, prefix = '/'): any {}
setNotFoundHandler(handler: Function, prefix = '/'): any {}
isHeadersSent(response: any): any {}
getHeader?(response: any, name: string) {}
setHeader(response: any, name: string, value: string): any {}
appendHeader?(response: any, name: string, value: string) {}
registerParserMiddleware(): any {}
enableCors(options: any): any {}
createMiddlewareFactory(requestMethod: RequestMethod): any {}
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) {
return response.getHeader(name);
}

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 8f4e945

Please sign in to comment.