-
Notifications
You must be signed in to change notification settings - Fork 8.3k
feat: add an option to allow trailing slash insensitive matching #4306
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
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #4306 +/- ##
==========================================
- Coverage 99.21% 98.92% -0.29%
==========================================
Files 42 44 +2
Lines 3182 3452 +270
==========================================
+ Hits 3157 3415 +258
- Misses 17 26 +9
- Partials 8 11 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if length := len(p); length > 1 && p[length-1] == '/' {
return p[:length-1];
}
$ go test -run=^$ -bench='TrimWith' -benchmem
goos: windows
goarch: amd64
pkg: github.com/gin-gonic/gin
cpu: Intel(R) Core(TM) i5-3570 CPU @ 3.40GHz
BenchmarkTrimWithHasSuffix-4 100000000 11.13 ns/op 0 B/op 0 allocs/op
BenchmarkTrimWithManualCheck-4 1000000000 0.2761 ns/op 0 B/op 0 allocs/op
PASS
ok github.com/PHPDevsr/gin-forked 1.586s
Keep this logic, faster than using strings.HasSuffix()
.
@ddevsr Hi, I kept the original logic |
Signed-off-by: Charlie Chiang <[email protected]>
Add an option
TrailingSlashInsensitivity
in engine to allow trailing slash insensitive matching, e.g., if a handler for/path
is defined,/path
and/path/
will go the the same handler without redirection responses.See the tests for details.
TrailingSlashInsensitivity
is disabled by default so existing behavior should not be affected.fixes #915