Skip to content

Commit

Permalink
address Issue-751 with method mismatch flag in Route.Match()
Browse files Browse the repository at this point in the history
  • Loading branch information
roy-kim-33 committed Oct 11, 2024
1 parent db9d1d0 commit daf8793
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions route.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,15 @@ func (r *Route) Match(req *http.Request, match *RouteMatch) bool {
}

var matchErr error
methodMismatch := false // Track method mismatch

// Match everything.
for _, m := range r.matchers {
if matched := m.Match(req, match); !matched {
// Detect mismatch due to HTTP method
if _, ok := m.(methodMatcher); ok {
matchErr = ErrMethodMismatch
methodMismatch = true // Flag method mismatch
continue
}

Expand Down Expand Up @@ -88,6 +91,13 @@ func (r *Route) Match(req *http.Request, match *RouteMatch) bool {
}
}

// If flagged method mismatch, return 405
if methodMismatch {
match.MatchErr = ErrMethodMismatch
return false
}

// No match errors, but handle method matches
if matchErr != nil {
match.MatchErr = matchErr
return false
Expand Down

0 comments on commit daf8793

Please sign in to comment.