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

env and @headers not available in before block when Method not allowed #1444

Closed
leifg opened this issue Jul 19, 2016 · 3 comments
Closed

env and @headers not available in before block when Method not allowed #1444

leifg opened this issue Jul 19, 2016 · 3 comments

Comments

@leifg
Copy link
Contributor

leifg commented Jul 19, 2016

Suppose you do this:

before do
  env['Something']
end

In general this is possible.

However if you run into a method not allowed, not only will this block executed, it also sets env (and @headers) to nil and throws an error that is never caught and will expose the stacktrace to the caller.

I created an example project here.

leifg added a commit to leifg/grape-method-not-allowed that referenced this issue Jul 19, 2016
@leifg
Copy link
Contributor Author

leifg commented Jul 19, 2016

Note: this runs the before filters in the Method not allowed context. I guess at this point env and @headers also should be initialized like it is done in the endpoint

@dblock
Copy link
Member

dblock commented Jul 19, 2016

This looks legit, I would turn your demo into a spec and PR a fix. Thanks.

@leifg leifg changed the title env and @herads not available in before block when Method not allowed env and @heraders not available in before block when Method not allowed Jul 19, 2016
@leifg leifg changed the title env and @heraders not available in before block when Method not allowed env and @headers not available in before block when Method not allowed Jul 19, 2016
@leifg
Copy link
Contributor Author

leifg commented Jul 19, 2016

opened the PR: #1446

@dblock dblock closed this as completed in 21925fc Jul 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants