可以看看类型声明
node_modules/@nestjs/common/decorators/http/route-params.decorator.d.ts
```typescript
/**
* The `@Response()`/`@Res` parameter decorator options.
*/
export interface ResponseDecoratorOptions {
/**
* Determines whether the response will be sent manually within the route handler,
* with the use of native response handling methods exposed by the platform-specific response object,
* or if it should passthrough Nest response processing pipeline.
*
* @
default false
*/
passthrough: boolean;
}
```
简单来说你的场景可以这样玩
```typescript
@
Post("/world")
getHello(@Res({ passthrough: true }) response: Response) {
response.setHeader("x-hello", "world");
return { msg: "Hello World!" };
}
```
拦截器也能生效
```typescript
@
Injectable()
export class RewritePost201To200Interruptor implements NestInterceptor {
intercept(context: ExecutionContext, next: CallHandler) {
const host = context.switchToHttp();
const request: Request = host.getRequest();
const response: Response = host.getResponse();
return next.handle().pipe(
map((data: unknown) => {
if (response.statusCode === HttpStatus.CREATED && request?.method.toUpperCase() === "POST") {
response.status(HttpStatus.OK);
}
return data;
}),
);
}
}
```
客户端也可以直接拿到返回