From 2ad06ce67efbd8c354b052fe9becc962e9ad6ef8 Mon Sep 17 00:00:00 2001 From: Vishal Rana Date: Sun, 22 Nov 2015 09:26:11 -0800 Subject: [PATCH] Fixed #265 Signed-off-by: Vishal Rana --- echo.go | 6 +++--- router.go | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/echo.go b/echo.go index 6d872602..7b76ccd4 100644 --- a/echo.go +++ b/echo.go @@ -162,9 +162,9 @@ var ( // Errors //-------- - UnsupportedMediaType = errors.New("echo ⇒ unsupported media type") - RendererNotRegistered = errors.New("echo ⇒ renderer not registered") - InvalidRedirectCode = errors.New("echo ⇒ invalid redirect status code") + UnsupportedMediaType = errors.New("unsupported media type") + RendererNotRegistered = errors.New("renderer not registered") + InvalidRedirectCode = errors.New("invalid redirect status code") //---------------- // Error handlers diff --git a/router.go b/router.go index 05451cd3..a3bba24b 100644 --- a/router.go +++ b/router.go @@ -266,6 +266,15 @@ func (n *node) findHandler(method string) HandlerFunc { } } +func (n *node) check405() HandlerFunc { + for _, m := range methods { + if h := n.findHandler(m); h != nil { + return methodNotAllowedHandler + } + } + return notFoundHandler +} + func (r *Router) Find(method, path string, ctx *Context) (h HandlerFunc, e *Echo) { h = notFoundHandler e = r.echo @@ -373,8 +382,11 @@ End: if cn.echo != nil { e = cn.echo } + + // NOTE: Slow zone... if h == nil { - h = methodNotAllowedHandler + h = cn.check405() + // Dig further for match-any, might have an empty value for *, e.g. // serving a directory. Issue #207. if cn = cn.findChildByKind(mkind); cn == nil { @@ -382,7 +394,7 @@ End: } ctx.pvalues[len(cn.pnames)-1] = "" if h = cn.findHandler(method); h == nil { - h = methodNotAllowedHandler + h = cn.check405() } } return