Repository navigation
Answer 404 when every route on a path cascades - #3043
Merged
Merged
Conversation
ericproulx
force-pushed
the
fix/cascading-routes-answer-404
branch
from
October 31, 2026 10:55
bc10b9a to
834d683
Compare
2 of 3 tasks
A route declines a request with X-Cascade: pass. The README documents the result for an invalid version under `cascade: true`: a 404 if no other route matches. The router only did that when one route had declined. With two or more routes on the path, #rotation handed back the last one's response, and since #2829 a cascading ANY route's response came back too, with its body already closed. So an unknown version answered 404 from an API with one version and 406 from an API with several. Rack::Cascade goes by the status alone, so that 406 also stopped it short of the next app, despite the X-Cascade header. A declined response is now always closed and dropped, leaving the router's own 404, which still carries X-Cascade. An ANY route that declined still matched, so no 405 follows it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ericproulx
force-pushed
the
fix/cascading-routes-answer-404
branch
from
October 31, 2026 14:42
834d683 to
126f705
Compare
Danger ReportNo issues found. |
3 of 4 tasks
ericproulx
added a commit
that referenced
this pull request
Oct 31, 2026
#settle and #neighbours handled two situations, no route matching and a route declining, and told them apart with a `cascaded` flag. That flag was true exactly when a route had matched, so it is replaced by two paths: #after_miss looks for the allowed methods and the ANY routes, #after_cascade tries the siblings and the ANY routes. #halt?, a predicate that closed a body as a side effect, goes with it. The names said something else, so: - `transaction` is `dispatch`: there is no atomicity or rollback in it. - `match?`, `greedy_match?` and `neighbour_match?` return a route, so they are `star_route_for`, `allowed_methods_route_for` and `neighbour_route_for`. - `GreedyRoute` is `AllowedMethodsRoute`: it matches on the path whatever the method, and only ever answers with the methods the path allows. Nothing in the ruby-grape org uses the constant outside this repo. The two lookups that repeated `routes.detect` go through `matched_route`. This is #3044, which merged into #3043's branch after #3043 had already merged, so it never reached master. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ericproulx
added a commit
that referenced
this pull request
Oct 31, 2026
#settle and #neighbours handled two situations, no route matching and a route declining, and told them apart with a `cascaded` flag. That flag was true exactly when a route had matched, so it is replaced by two paths: #after_miss looks for the allowed methods and the ANY routes, #after_cascade tries the siblings and the ANY routes. #halt?, a predicate that closed a body as a side effect, goes with it. The names said something else, so: - `transaction` is `dispatch`: there is no atomicity or rollback in it. - `match?`, `greedy_match?` and `neighbour_match?` return a route, so they are `star_route_for`, `allowed_methods_route_for` and `neighbour_route_for`. - `GreedyRoute` is `AllowedMethodsRoute`: it matches on the path whatever the method, and only ever answers with the methods the path allows. Nothing in the ruby-grape org uses the constant outside this repo. The two lookups that repeated `routes.detect` go through `matched_route`. This is #3044, which merged into #3043's branch after #3043 had already merged, so it never reached master. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A route declines a request with
X-Cascade: pass, as a version declared withcascade: truedoes for a version it doesn't serve. The README documents what follows: "a406 Not Acceptableerror is returned if the:cascadeoption is set tofalse. Otherwise a404 Not Founderror is returned by Rack if no other route matches."The router only did that when exactly one route had declined:
GET /xwith an unknown versioncascade: truecascade: trueroute :any,cascade: truecascade: falsecascade: falseThe number of versions shouldn't change the status. It also breaks
Rack::Cascade, which goes by the status alone: the 406 stopped it short of the next app, despite theX-Cascade: passheader.A declined response is now always closed and dropped, leaving the router's own 404, which still carries
X-Cascade. As a side effect the router no longer returns a cascading ANY route's response with its body already closed. An ANY route that declined still matched, so no 405 follows it, as before.Contract change
The two-or-more-versions 406 is long-standing (it's there in v3.3.5, the oldest release I ran), so clients may rely on it. Hence the UPGRADING entry, including how to keep the 406:
cascade: falseon the last version only. On an earlier version it makes the later versions unreachable.The status, headers and body of a declined response are dropped in every case now, where before they survived only with two or more routes on the path.
Test plan
Rack::Cascade.bundle exec rake: RuboCop clean, 3167 examples, 0 failures.🤖 Generated with Claude Code