Skip to content

Commit 9638c18

Browse files
performance(core) add headers check
1 parent 9ef356b commit 9638c18

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

packages/core/router/router-execution-context.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { RouteParamsMetadata } from '@nestjs/common/decorators';
1616
import { RouteParamtypes } from '@nestjs/common/enums/route-paramtypes.enum';
1717
import { Controller, Transform } from '@nestjs/common/interfaces';
1818
import {
19+
isEmpty,
1920
isFunction,
2021
isString,
2122
isUndefined,
@@ -248,15 +249,18 @@ export class RouterExecutionContext {
248249
) {
249250
const renderTemplate = this.reflectRenderTemplate(callback);
250251
const responseHeaders = this.reflectResponseHeaders(callback);
252+
const hasCustomHeaders = !isEmpty(responseHeaders);
251253

252254
if (renderTemplate) {
253255
return async (result, res) => {
254-
this.responseController.setHeaders(res, responseHeaders);
256+
hasCustomHeaders &&
257+
this.responseController.setHeaders(res, responseHeaders);
255258
await this.responseController.render(result, res, renderTemplate);
256259
};
257260
}
258261
return async (result, res) => {
259-
this.responseController.setHeaders(res, responseHeaders);
262+
hasCustomHeaders &&
263+
this.responseController.setHeaders(res, responseHeaders);
260264

261265
!isResponseHandled &&
262266
(await this.responseController.apply(result, res, httpStatusCode));

0 commit comments

Comments
 (0)