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

Rework routeDispatchTries + endpoint lookup for more intuitive 404/405 responses. #52

Merged
merged 4 commits into from Nov 15, 2021

Conversation

megri
Copy link
Contributor

@megri megri commented May 18, 2021

Prevent cask from responding with 405 for an undefined route.
Fixes #51.

Prior to this commit, prepareRouteTries created a mapping from
method-name to DispatchTrie (Map[String, DispatchTrie[…]]).

This commit instead creates a DispatchTrie[Map[String, …]],
basically an inversion of the previous result.

The updated tests in minimalApplication and minimalApplication2
have been updated to cover the differences.

@megri megri force-pushed the master branch 3 times, most recently from 0caaba0 to d3825ff Compare May 18, 2021 21:34
Fixes com-lihaoyi#51.

Prior to this commit, `prepareRouteTries` created a mapping from
method-name to DispatchTrie (Map[String, DispatchTrie[…]]).

This commit instead creates a DispatchTrie[Map[String, …]],
basically an inversion of the previous result.

The updated tests in minimalApplication and minimalApplication2
have been updated to cover the differences.
@megri
Copy link
Contributor Author

megri commented Nov 12, 2021

This PR is probably pretty stale by now. Still, it'd be nice to at least get some form of feedback on the hours spent..

@lihaoyi
Copy link
Member

lihaoyi commented Nov 15, 2021

@megri could you provide a proper PR description of what your change is doing and how it fixes the problem? That would make it much easier to review and merge

@megri
Copy link
Contributor Author

megri commented Nov 15, 2021

@megri could you provide a proper PR description of what your change is doing and how it fixes the problem? That would make it much easier to review and merge

I updated the PR with the commit message of the final commit. There is some cleanup/unrelated commits in the PR as well. I can remove those if so desired.

@lihaoyi lihaoyi merged commit 0e7ee84 into com-lihaoyi:master Nov 15, 2021
@lihaoyi
Copy link
Member

lihaoyi commented Nov 15, 2021

@megri looks great, sorry for the delay in getting to this. Have not been on top of maintenance last few months

lihaoyi added a commit that referenced this pull request May 6, 2022
This regressed in #52, resulting in both false positives (where a `GET` and a `POST` shared the same route, giving an unnecessary error) and false negatives (where multiple `GET`s sharing the same route failed to create an error). The basic problem was that since combining the various HTTP methods into a single routing trie, the old logic comparing uniqueness/duplication/etc. was no longer correct in the new combined trie.

This PR fixes it by doing a `groupBy` to split up the entries in the combined trie by HTTP method, before running essentially the same validation.

We augment the test suite, tightening up cask/test/src/test/cask/DispatchTrieTests.scala to make it stricter, checking exact error messages to ensure we get not just any failure but the *correct* failure when the validation code triggers. This should hopefully catch this sort of regression in future.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cask returns 405 for an undefined route that uses a method not used by other routes.
2 participants