1
0
mirror of https://github.com/labstack/echo.git synced 2024-11-24 08:22:21 +02:00
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana 2015-11-22 09:26:11 -08:00
parent 4f996419e1
commit 2ad06ce67e
2 changed files with 17 additions and 5 deletions

View File

@ -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

View File

@ -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