@@ -83,7 +83,7 @@ export class RouterExecutionContext {
8383 fnHandleResponse,
8484 paramtypes,
8585 getParamsMetadata,
86- } = this . getMetadata ( instance , callback , methodName , module , requestMethod ) ;
86+ } = this . getMetadata ( instance , callback , methodName , module ) ;
8787 const paramsOptions = this . contextUtils . mergeParamsMetatypes (
8888 getParamsMetadata ( module , contextId , inquirerId ) ,
8989 paramtypes ,
@@ -131,6 +131,20 @@ export class RouterExecutionContext {
131131 const args = this . contextUtils . createNullArray ( argsLength ) ;
132132 fnCanActivate && ( await fnCanActivate ( [ req , res ] ) ) ;
133133
134+ const httpCode = this . reflectHttpStatusCode ( callback ) ;
135+
136+ const httpStatusCode = httpCode
137+ ? httpCode
138+ : this . responseController . getStatusByMethod ( requestMethod ) ;
139+
140+ this . responseController . status ( res , httpStatusCode ) ;
141+
142+ const responseHeaders = this . reflectResponseHeaders ( callback ) ;
143+ const hasCustomHeaders = ! isEmpty ( responseHeaders ) ;
144+
145+ hasCustomHeaders &&
146+ this . responseController . setHeaders ( res , responseHeaders ) ;
147+
134148 const result = await this . interceptorsConsumer . intercept (
135149 interceptors ,
136150 [ req , res ] ,
@@ -146,8 +160,7 @@ export class RouterExecutionContext {
146160 instance : Controller ,
147161 callback : ( ...args : any [ ] ) => any ,
148162 methodName : string ,
149- module : string ,
150- requestMethod : RequestMethod ,
163+ module : string
151164 ) : HandlerMetadata {
152165 const cacheMetadata = this . handlerMetadataStorage . get ( instance , methodName ) ;
153166 if ( cacheMetadata ) {
@@ -165,7 +178,6 @@ export class RouterExecutionContext {
165178 instance ,
166179 methodName ,
167180 ) ;
168- const httpCode = this . reflectHttpStatusCode ( callback ) ;
169181 const getParamsMetadata = (
170182 moduleKey : string ,
171183 contextId = STATIC_CONTEXT ,
@@ -184,14 +196,10 @@ export class RouterExecutionContext {
184196 ( { type } ) =>
185197 type === RouteParamtypes . RESPONSE || type === RouteParamtypes . NEXT ,
186198 ) ;
187- const httpStatusCode = httpCode
188- ? httpCode
189- : this . responseController . getStatusByMethod ( requestMethod ) ;
190199
191200 const fnHandleResponse = this . createHandleResponseFn (
192201 callback ,
193- isResponseHandled ,
194- httpStatusCode ,
202+ isResponseHandled
195203 ) ;
196204 const handlerMetadata : HandlerMetadata = {
197205 argsLength,
@@ -342,23 +350,16 @@ export class RouterExecutionContext {
342350 public createHandleResponseFn (
343351 callback : ( ...args : any [ ] ) => any ,
344352 isResponseHandled : boolean ,
345- httpStatusCode : number ,
353+ httpStatusCode ? : number
346354 ) {
347355 const renderTemplate = this . reflectRenderTemplate ( callback ) ;
348- const responseHeaders = this . reflectResponseHeaders ( callback ) ;
349- const hasCustomHeaders = ! isEmpty ( responseHeaders ) ;
350356
351357 if ( renderTemplate ) {
352358 return async < TResult , TResponse > ( result : TResult , res : TResponse ) => {
353- hasCustomHeaders &&
354- this . responseController . setHeaders ( res , responseHeaders ) ;
355359 await this . responseController . render ( result , res , renderTemplate ) ;
356360 } ;
357361 }
358362 return async < TResult , TResponse > ( result : TResult , res : TResponse ) => {
359- hasCustomHeaders &&
360- this . responseController . setHeaders ( res , responseHeaders ) ;
361-
362363 result = await this . responseController . transformToResult ( result ) ;
363364 ! isResponseHandled &&
364365 ( await this . responseController . apply ( result , res , httpStatusCode ) ) ;
0 commit comments