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:
parent
86ddfedb45
commit
296498c942
@ -325,4 +325,5 @@ func (c *context) reset(req engine.Request, res engine.Response) {
|
|||||||
c.response = res
|
c.response = res
|
||||||
c.query = nil
|
c.query = nil
|
||||||
c.store = nil
|
c.store = nil
|
||||||
|
c.handler = notFoundHandler
|
||||||
}
|
}
|
||||||
|
6
echo.go
6
echo.go
@ -141,12 +141,6 @@ const (
|
|||||||
WWWAuthenticate = "WWW-Authenticate"
|
WWWAuthenticate = "WWW-Authenticate"
|
||||||
XForwardedFor = "X-Forwarded-For"
|
XForwardedFor = "X-Forwarded-For"
|
||||||
XRealIP = "X-Real-IP"
|
XRealIP = "X-Real-IP"
|
||||||
|
|
||||||
//-----------
|
|
||||||
// Protocols
|
|
||||||
//-----------
|
|
||||||
|
|
||||||
WebSocket = "websocket"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -222,22 +222,22 @@ func TestEchoGroup(t *testing.T) {
|
|||||||
return h.Handle(c)
|
return h.Handle(c)
|
||||||
})
|
})
|
||||||
}))
|
}))
|
||||||
g1.Get("/", h)
|
g1.Get("", h)
|
||||||
|
|
||||||
// Nested groups
|
// Nested groups
|
||||||
g2 := e.Group("/group2")
|
g2 := e.Group("/group2")
|
||||||
g3 := g2.Group("/group3")
|
g3 := g2.Group("/group3")
|
||||||
g3.Get("/", h)
|
g3.Get("", h)
|
||||||
|
|
||||||
request(GET, "/users", e)
|
request(GET, "/users", e)
|
||||||
assert.Equal(t, "0", buf.String())
|
assert.Equal(t, "0", buf.String())
|
||||||
|
|
||||||
buf.Reset()
|
buf.Reset()
|
||||||
request(GET, "/group1/", e)
|
request(GET, "/group1", e)
|
||||||
assert.Equal(t, "01", buf.String())
|
assert.Equal(t, "01", buf.String())
|
||||||
|
|
||||||
buf.Reset()
|
buf.Reset()
|
||||||
c, _ := request(GET, "/group2/group3/", e)
|
c, _ := request(GET, "/group2/group3", e)
|
||||||
assert.Equal(t, http.StatusOK, c)
|
assert.Equal(t, http.StatusOK, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
group.go
2
group.go
@ -61,7 +61,7 @@ func (g *Group) Match(methods []string, path string, handler Handler, middleware
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *Group) Group(prefix string, m ...Middleware) *Group {
|
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) {
|
func (g *Group) add(method, path string, handler Handler, middleware ...Middleware) {
|
||||||
|
@ -25,11 +25,6 @@ const (
|
|||||||
func BasicAuth(fn BasicAuthFunc, options ...*BasicAuthOptions) echo.MiddlewareFunc {
|
func BasicAuth(fn BasicAuthFunc, options ...*BasicAuthOptions) echo.MiddlewareFunc {
|
||||||
return func(next echo.Handler) echo.Handler {
|
return func(next echo.Handler) echo.Handler {
|
||||||
return echo.HandlerFunc(func(c echo.Context) error {
|
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)
|
auth := c.Request().Header().Get(echo.Authorization)
|
||||||
l := len(basic)
|
l := len(basic)
|
||||||
|
|
||||||
|
@ -282,8 +282,6 @@ func (n *node) check405() HandlerFunc {
|
|||||||
|
|
||||||
func (r *Router) Find(method, path string, context Context) {
|
func (r *Router) Find(method, path string, context Context) {
|
||||||
ctx := context.Object()
|
ctx := context.Object()
|
||||||
// h = notFoundHandler
|
|
||||||
// e = r.echo
|
|
||||||
cn := r.tree // Current node as root
|
cn := r.tree // Current node as root
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
Loading…
Reference in New Issue
Block a user