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

Allow ctrl.before to prevent further processing of the request #1023

Merged
merged 1 commit into from
Sep 16, 2014

Conversation

pluma
Copy link
Contributor

@pluma pluma commented Sep 15, 2014

A useful (but apparently unintended) use of ctrl.before is to impose access restrictions.

Currently the only way to prevent further processing of a request in ctrl.before is to throw an exception. But this yields a route handling error, which results in a stacktrace returned as plaintext response. This is less than ideal.

This change allows ctrl.before callbacks to explicitly return false to prevent any further processing of the request. As the response body can be accessed in ctrl.before callbacks already, this also provides a workaround for use cases requiring intercepting all supported HTTP verbs in a single function.

Returning false to prevent further processing should be familiar to many JS devs from client-side event handling and libraries like underscore.

@moonglum, @fceller does this make any sense to you?

@moonglum
Copy link

Yes, it does.

moonglum added a commit that referenced this pull request Sep 16, 2014
Allow ctrl.before to prevent further processing of the request
@moonglum moonglum merged commit 6c2c26a into devel Sep 16, 2014
@moonglum moonglum deleted the foxx-before-guard branch September 16, 2014 08:51
@myguidingstar-zz
Copy link

the "returns false" feature has not been documented yet


Edited: I was looking at master branch instead of devel. It is documented. Sorry for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants