Repository navigation
Ignore trailing slash - #32
Merged
Merged
Conversation
…thods) & add tests
pawndev
previously approved these changes
Jun 23, 2024
pawndev
left a comment
Collaborator
There was a problem hiding this comment.
Nice feature ! Thanks for that, buddy 🙏
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #32 +/- ##
==========================================
+ Coverage 88.08% 88.23% +0.15%
==========================================
Files 12 12
Lines 1678 1726 +48
==========================================
+ Hits 1478 1523 +45
- Misses 169 171 +2
- Partials 31 32 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
pawndev
previously approved these changes
Jun 24, 2024
…thods) also when redirect trailing slash.
swafran
approved these changes
Jun 24, 2024
| // Shouldn't send the body for POST or HEAD; that leaves GET. | ||
| if !hadCT && r.Method == "GET" { | ||
| body := "<a href=\"" + htmlEscape(path) + "\">" + http.StatusText(code) + "</a>.\n" | ||
| _, _ = fmt.Fprintln(w, body) |
Check warning
Code scanning / CodeQL
Reflected cross-site scripting
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
This pull request introduces a new feature to Fox: the ability to ignore trailing slashes in URL paths. While redirecting or ignoring trailing slashes for an API endpoint is not typically advised, it may be desirable for websites. Both methods have their pros and cons, and most routers, including Fox, choose to redirect the client with a 301 status code for trailing slashes.
For example,
https://apple.com/iphoneredirects you tohttps://apple.com/iphone/with a 301 Moved Permanently, whilehttps://github.com/tigerwill90/fox/andhttps://github.com/tigerwill90/foxboth match the same resource without any redirection.This new feature allows the router to handle requests regardless of the presence or absence of a trailing slash.
Details
WithIgnoreTrailingSlashandWithRedirectTrailingSlashoptions are mutually exclusive. If both are enabled,WithIgnoreTrailingSlashtakes precedence.Example
In this example, all the following requests match a handler:
/articles/articles//articles/12/articles/51/Consistent Behavior with Tree API
The Tree API allows the user to access lower-level functions like
Match,Has,Methods, andLookup, which may be useful for managing routes at runtime. These methods will also ignore the trailing slash if the option is enabled.Bug Fix
An edge case has been fixed for both the redirect trailing slash and the new ignore trailing slash feature. In some scenarios, the router would miss a possible redirect recommendation if the path exactly matched an intermediary node (without a handler).
In this circumstance,
/foo/can be redirected to/foobut was previously missed by the router. Now, the lookup function correctly handles this edge case.Benchmark Differential
Expect none or negligible impact on performance.
Path to v1.0.0
We are gradually moving towards the v1.0.0 release. While some API inconsistencies remain, along with necessary code cleanup and documentation updates, we anticipate reaching v1.0.0 during the summer.