Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading