Skip to content

Commit

Permalink
feat: enable ignore trailing slash for tree method (has, match and me…
Browse files Browse the repository at this point in the history
…thods) & add tests
  • Loading branch information
tigerwill90 committed Jun 23, 2024
1 parent 5de4cae commit eb89c7d
Show file tree
Hide file tree
Showing 4 changed files with 544 additions and 41 deletions.
15 changes: 8 additions & 7 deletions fox.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func New(opts ...Option) *Router {
func (fox *Router) NewTree() *Tree {
tree := new(Tree)
tree.mws = fox.mws
tree.ignoreTrailingSlash = fox.ignoreTrailingSlash

// Pre instantiate nodes for common http verb
nds := make([]*node, len(commonVerbs))
Expand Down Expand Up @@ -315,17 +316,17 @@ func (fox *Router) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}

if r.Method != http.MethodConnect && r.URL.Path != "/" && tsr {
if fox.redirectTrailingSlash && target == CleanPath(target) {
// Reset params as it may have recorded wildcard segment (the context may still be used in a middleware)
*c.params = (*c.params)[:0]
fox.tsrRedirect(c)
if fox.ignoreTrailingSlash {
c.path = n.path
n.handler(c)
c.Close()
return
}

if fox.ignoreTrailingSlash {
c.path = n.path
n.handler(c)
if fox.redirectTrailingSlash && target == CleanPath(target) {
// Reset params as it may have recorded wildcard segment (the context may still be used in a middleware)
*c.params = (*c.params)[:0]
fox.tsrRedirect(c)
c.Close()
return
}
Expand Down
Loading

0 comments on commit eb89c7d

Please sign in to comment.