Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(controller): removes response.send from route handler #1622

Merged
merged 1 commit into from
Dec 19, 2022

Conversation

lastikas
Copy link
Contributor

Calling response.send in the controller prevents interceptos from being able to modify the response object further down the line like, for example, setting headers

It's important to notice that a custom controller that extends the PrometheusController in the same manner as the one in the spec will stop working after this modification

This should be easy to test with a simple interceptor

@Injectable()
export class CustomInterceptor implements NestInterceptor {
  intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
    const res = context.switchToHttp().getResponse<Response>();
    return next.handle().pipe(
      tap(() => {
        res.setHeader('x-test', 'test');
      }),
    );
  }
}

@willsoto
Copy link
Owner

Thanks. This seems reasonable enough.

One question regarding this:

It's important to notice that a custom controller that extends the PrometheusController in the same manner as the one in the spec will stop working after this modification

Would you consider this a breaking change then?

@lastikas
Copy link
Contributor Author

Would you consider this a breaking change then?

Yes, this is a breaking change

I can see some projects that would suffer from this here: https://github.com/search?q=extends+PrometheusController&type=Code

@willsoto
Copy link
Owner

And what would be the upgrade path for users? I'd like to document the breaking change and explain how to fix it.

calling response.send in the controller prevents interceptos from
being able to modify the response object further down the line
like, for example, setting headers
@lastikas lastikas force-pushed the feat/return-from-controller branch from 75dfb13 to 1c12df7 Compare December 19, 2022 14:40
@lastikas
Copy link
Contributor Author

And what would be the upgrade path for users? I'd like to document the breaking change and explain how to fix it.

On that note I've just added a modification to the README as well

Basically anyone who extends the Controller and uses await super.index(response); should instead use return super.index(response);

@willsoto willsoto merged commit bfa6c70 into willsoto:main Dec 19, 2022
willsoto pushed a commit that referenced this pull request Dec 19, 2022
# [5.0.0](v4.7.0...v5.0.0) (2022-12-19)

### Bug Fixes

* **controller:** removes response.send from route handler ([#1622](#1622)) ([bfa6c70](bfa6c70))

### BREAKING CHANGES

* **controller:** For users that have a custom subclass, you will need to adjust the method to `return super.index(response);` as the base class no longer sends a response.
@willsoto
Copy link
Owner

🎉 This PR is included in version 5.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@lastikas lastikas deleted the feat/return-from-controller branch December 19, 2022 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants