Browse Source

Potential fix for #20

pull/139/head
bign8 10 years ago committed by Nate Woods
parent
commit
c329c7d193
  1. 13
      mux.go

13
mux.go

@ -59,6 +59,12 @@ func (r *Router) Match(req *http.Request, match *RouteMatch) bool {
return true return true
} }
} }
// Closest match for a router (includes sub-routers)
if r.NotFoundHandler != nil {
match.Handler = r.NotFoundHandler
return true
}
return false return false
} }
@ -88,12 +94,9 @@ func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request) {
setVars(req, match.Vars) setVars(req, match.Vars)
setCurrentRoute(req, match.Route) setCurrentRoute(req, match.Route)
} }
if handler == nil {
handler = r.NotFoundHandler
if handler == nil { if handler == nil {
handler = http.NotFoundHandler() handler = http.NotFoundHandler()
} }
}
if !r.KeepContext { if !r.KeepContext {
defer context.Clear(req) defer context.Clear(req)
} }
@ -324,11 +327,15 @@ func CurrentRoute(r *http.Request) *Route {
} }
func setVars(r *http.Request, val interface{}) { func setVars(r *http.Request, val interface{}) {
if val != nil {
context.Set(r, varsKey, val) context.Set(r, varsKey, val)
}
} }
func setCurrentRoute(r *http.Request, val interface{}) { func setCurrentRoute(r *http.Request, val interface{}) {
if val != nil {
context.Set(r, routeKey, val) context.Set(r, routeKey, val)
}
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

Loading…
Cancel
Save