Skip to content

Commit

Permalink
Potential fix for #20
Browse files Browse the repository at this point in the history
  • Loading branch information
bign8 committed Dec 25, 2015
1 parent 9c068cf commit c329c7d
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ func (r *Router) Match(req *http.Request, match *RouteMatch) bool {
return true
}
}

// Closest match for a router (includes sub-routers)
if r.NotFoundHandler != nil {
match.Handler = r.NotFoundHandler
return true
}
return false
}

Expand Down Expand Up @@ -89,10 +95,7 @@ func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request) {
setCurrentRoute(req, match.Route)
}
if handler == nil {
handler = r.NotFoundHandler
if handler == nil {
handler = http.NotFoundHandler()
}
handler = http.NotFoundHandler()
}
if !r.KeepContext {
defer context.Clear(req)
Expand Down Expand Up @@ -324,11 +327,15 @@ func CurrentRoute(r *http.Request) *Route {
}

func setVars(r *http.Request, val interface{}) {
context.Set(r, varsKey, val)
if val != nil {
context.Set(r, varsKey, val)
}
}

func setCurrentRoute(r *http.Request, val interface{}) {
context.Set(r, routeKey, val)
if val != nil {
context.Set(r, routeKey, val)
}
}

// ----------------------------------------------------------------------------
Expand Down

0 comments on commit c329c7d

Please sign in to comment.