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

Using route :any causes OPTIONS and HEAD requests to fail #1056

Closed
ekampp opened this issue Jul 7, 2015 · 5 comments
Closed

Using route :any causes OPTIONS and HEAD requests to fail #1056

ekampp opened this issue Jul 7, 2015 · 5 comments
Labels

Comments

@ekampp
Copy link
Contributor

ekampp commented Jul 7, 2015

According to the documentation, any GET endpoint also serves OPTIONS and HEAD requests.

I would expect these to be hit before the route :any at the bottom of my api. But this isn't the case.

Is this a bug or intentional? If it's intentional, what's the right way to catch stray requests without overriding OPTIONS and HEAD for the real endpoints?

route :any, '*path' do
  raise NotFound, 'Path not NotFound'
end

Here is a demo api. I would expect this request to return the Allow header for the /names endpoint. But instead it return I'm not here, which means it hits the route :any fallback.

OPTIONS /names
@dblock
Copy link
Member

dblock commented Jul 7, 2015

You should turn it into a test, do GETs behave differently from HEADs?

@dblock dblock added the bug? label Jul 7, 2015
@ekampp
Copy link
Contributor Author

ekampp commented Jul 7, 2015

@dblock any suggestions as to where to start adding a test?

If I understand your question right, then yes: HEAD behaves differently from GET. HEAD doesn't return any response body - only headers. It's so to speak a compacted request. Useful for checking if a cache is busted, and a new one should be fetched.

@dblock
Copy link
Member

dblock commented Jul 7, 2015

For now just add a standalone test in https://github.com/intridea/grape/tree/master/spec/grape/integration.

ekampp added a commit to ekampp/grape that referenced this issue Jul 7, 2015
This illustrates the issue described in ruby-grape#1056 by adding a options and
head request when the catch-all route is enabled.
ekampp added a commit to ekampp/grape that referenced this issue Jul 15, 2015
This illustrates the issue described in ruby-grape#1056 by adding a options and
head request when the catch-all route is enabled.
@arempe93
Copy link
Contributor

arempe93 commented Feb 2, 2016

@ekampp @dblock closed by #1263?

@dblock
Copy link
Member

dblock commented Feb 2, 2016

Yes.

@dblock dblock closed this as completed Feb 2, 2016
namusyaka pushed a commit to namusyaka/grape that referenced this issue Mar 16, 2016
This illustrates the issue described in ruby-grape#1056 by adding a options and
head request when the catch-all route is enabled.
przbadu pushed a commit to przbadu/grape that referenced this issue Apr 5, 2016
This illustrates the issue described in ruby-grape#1056 by adding a options and
head request when the catch-all route is enabled.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants