X-Cascade and Rails

338 views
Skip to first unread message

André Dieb

unread,
Feb 15, 2013, 3:57:51 PM2/15/13
to ruby-...@googlegroups.com
Hello,

I have an API mounted on rails with header versioning and strict set to true. I expected to get 406 errors whenever a wrong vendor/version was passed, but I'm getting ActionController::RoutingError.

After digging a while, it seems that grape is passing "X-Cascade: pass" up, which makes Rails try to look for other routes.

Any suggestions on disabling this behaviour on Rails? At least for my API prefix?

Cheers

--
André Dieb Martins

Daniel Doubrovkine

unread,
Feb 16, 2013, 7:07:49 PM2/16/13
to ruby-...@googlegroups.com
A possible solution is to add a match right below your API in routes.rb that will match anything left on, say, api/* and terminate the request there.

But do you really want a different result if Rails fails to match a route vs. API? 

Fyi, this is implemented in https://github.com/intridea/grape/blob/master/lib/grape/middleware/versioner/header.rb. I suppose a clean PR that adds an option to header versionning to change this behavior could be ok too.

--
You received this message because you are subscribed to the Google Groups "Grape Framework Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-grape+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--

dB. | Moscow - Geneva - Seattle - New York
dblock.org - @dblockdotorg

André Dieb

unread,
Feb 17, 2013, 11:20:51 AM2/17/13
to ruby-...@googlegroups.com
Hi Daniel,

I'll try your suggestion, thanks!

On my debugging session, I got to read some of Rack's code and found out that it once it looks at the X-Cascade => 'pass', it completely ignores the previous status code and places a 404 instead.

On my test scenario, my client sends on purpose a wrong vendor and the expecter result is a 406 error. Because of the cascading, I'm getting a 404 instead. In this scenario, it may not be acceptable for rails to lookup another route.

I'll try to create a simple test scenario and PR adding an option to header versioning.

Thanks,

André Dieb Martins
Reply all
Reply to author
Forward
0 new messages