Skip to content

Commit

Permalink
feat: small behaviour fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tigerwill90 committed Oct 13, 2024
1 parent f90e99b commit 29d1f69
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 20 deletions.
18 changes: 0 additions & 18 deletions fox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,24 +643,6 @@ func TestStaticRouteMalloc(t *testing.T) {
}
}

func TestRoute_HandleMiddlewareMalloc(t *testing.T) {
f := New()
for _, rte := range githubAPI {
require.NoError(t, f.Tree().Handle(rte.method, rte.path, emptyHandler))
}

for _, rte := range githubAPI {
req := httptest.NewRequest(rte.method, rte.path, nil)
w := httptest.NewRecorder()
r, c, _ := f.Lookup(&recorder{ResponseWriter: w}, req)
allocs := testing.AllocsPerRun(100, func() {
r.HandleMiddleware(c)
})
c.Close()
assert.Equal(t, float64(0), allocs)
}
}

func TestParamsRoute(t *testing.T) {
rx := regexp.MustCompile("({|\\*{)[A-z]+[}]")
r := New()
Expand Down
5 changes: 3 additions & 2 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,12 @@ func WithIgnoreTrailingSlash(enable bool) Option {
// - Setting the strategy to nil is equivalent to no strategy configured.
func WithClientIPStrategy(strategy ClientIPStrategy) Option {
return optionFunc(func(router *Router, route *Route) {
if router != nil {
router.ipStrategy = cmp.Or(strategy, ClientIPStrategy(noClientIPStrategy{}))
if router != nil && strategy != nil {
router.ipStrategy = strategy
}

if route != nil {
// Apply no strategy if nil provided.
route.ipStrategy = cmp.Or(strategy, ClientIPStrategy(noClientIPStrategy{}))
}
})
Expand Down

0 comments on commit 29d1f69

Please sign in to comment.