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

Run onSend hooks when an encapsulated handler invokes the notFound handler #870

Merged
merged 3 commits into from Apr 3, 2018

Conversation

nwoltman
Copy link
Contributor

@nwoltman nwoltman commented Apr 1, 2018

If a route is encapsulated, it may have more onSend hooks than the notFound handler associated with the route. This PR makes sure that if a route invokes the notFound handler, all of the route's onSend hooks will run.

Fixes #868

Checklist

  • run npm run test and npm run benchmark
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message and code follows Code of conduct

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How much this affects benchmarks (404 with onSend hooks)?

Can we pre-compute the list instead? Adding the hooks to the 404 context as well during boot?

lib/reply.js Outdated
reply.context = reply.context._404Context
reply.context.handler(reply.request, reply)
// Use a copy of the 404 context with the original context's onSend hooks
const context = Object.assign({}, reply.context._404Context)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use prototypical inheritance here (Object.create..)? So that we avoid a full copy, the context is big and assign is slow.

lib/reply.js Outdated
// Use a copy of the 404 context with the original context's onSend hooks
const context = Object.assign({}, reply.context._404Context)
context.onSend = reply.context.onSend
reply.context = context
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make all this block optional, only if there are onSend hooks?

@delvedor delvedor added the bugfix Issue or PR that should land as semver patch label Apr 1, 2018
Copy link
Member

@delvedor delvedor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Can you also upper case the F here?

reply.code(404).send(new Error('Not found'))

In this way the message is the same as the spec.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@delvedor delvedor merged commit cc2f9c9 into fastify:master Apr 3, 2018
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bugfix Issue or PR that should land as semver patch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants