Rework routeDispatchTries + endpoint lookup for more intuitive 404/405 responses.#52
Merged
lihaoyi merged 4 commits intocom-lihaoyi:masterfrom Nov 15, 2021
Merged
Rework routeDispatchTries + endpoint lookup for more intuitive 404/405 responses.#52lihaoyi merged 4 commits intocom-lihaoyi:masterfrom
lihaoyi merged 4 commits intocom-lihaoyi:masterfrom
Conversation
0caaba0 to
d3825ff
Compare
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.
Contributor
Author
|
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.. |
Member
|
@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 |
Contributor
Author
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. |
Member
|
@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.
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.
Prevent cask from responding with 405 for an undefined route.
Fixes #51.
Prior to this commit,
prepareRouteTriescreated a mapping frommethod-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.