1
0
mirror of https://github.com/labstack/echo.git synced 2024-12-24 20:14:31 +02:00

Fixed nested groups, reset Context#handler

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana 2016-03-08 19:31:11 -08:00
parent 86ddfedb45
commit 296498c942
6 changed files with 6 additions and 18 deletions

View File

@ -325,4 +325,5 @@ func (c *context) reset(req engine.Request, res engine.Response) {
c.response = res
c.query = nil
c.store = nil
c.handler = notFoundHandler
}

View File

@ -141,12 +141,6 @@ const (
WWWAuthenticate = "WWW-Authenticate"
XForwardedFor = "X-Forwarded-For"
XRealIP = "X-Real-IP"
//-----------
// Protocols
//-----------
WebSocket = "websocket"
)
var (

View File

@ -222,22 +222,22 @@ func TestEchoGroup(t *testing.T) {
return h.Handle(c)
})
}))
g1.Get("/", h)
g1.Get("", h)
// Nested groups
g2 := e.Group("/group2")
g3 := g2.Group("/group3")
g3.Get("/", h)
g3.Get("", h)
request(GET, "/users", e)
assert.Equal(t, "0", buf.String())
buf.Reset()
request(GET, "/group1/", e)
request(GET, "/group1", e)
assert.Equal(t, "01", buf.String())
buf.Reset()
c, _ := request(GET, "/group2/group3/", e)
c, _ := request(GET, "/group2/group3", e)
assert.Equal(t, http.StatusOK, c)
}

View File

@ -61,7 +61,7 @@ func (g *Group) Match(methods []string, path string, handler Handler, middleware
}
func (g *Group) Group(prefix string, m ...Middleware) *Group {
return g.echo.Group(prefix, m...)
return g.echo.Group(g.prefix+prefix, m...)
}
func (g *Group) add(method, path string, handler Handler, middleware ...Middleware) {

View File

@ -25,11 +25,6 @@ const (
func BasicAuth(fn BasicAuthFunc, options ...*BasicAuthOptions) echo.MiddlewareFunc {
return func(next echo.Handler) echo.Handler {
return echo.HandlerFunc(func(c echo.Context) error {
// Skip WebSocket
if (c.Request().Header().Get(echo.Upgrade)) == echo.WebSocket {
return nil
}
auth := c.Request().Header().Get(echo.Authorization)
l := len(basic)

View File

@ -282,8 +282,6 @@ func (n *node) check405() HandlerFunc {
func (r *Router) Find(method, path string, context Context) {
ctx := context.Object()
// h = notFoundHandler
// e = r.echo
cn := r.tree // Current node as root
var (