mirror of
https://github.com/labstack/echo.git
synced 2024-12-24 20:14:31 +02:00
parent
b855b5d507
commit
4f08fed018
@ -133,12 +133,12 @@ func WrapHandler(h fasthttp.RequestHandler) echo.HandlerFunc {
|
||||
}
|
||||
|
||||
// WrapMiddleware wraps `fasthttp.RequestHandler` into `echo.MiddlewareFunc`
|
||||
func WrapMiddleware(m fasthttp.RequestHandler) echo.MiddlewareFunc {
|
||||
func WrapMiddleware(h fasthttp.RequestHandler) echo.MiddlewareFunc {
|
||||
return func(next echo.Handler) echo.Handler {
|
||||
return echo.HandlerFunc(func(c echo.Context) error {
|
||||
ctx := c.Request().Object().(*fasthttp.RequestCtx)
|
||||
if !c.Response().Committed() {
|
||||
m(ctx)
|
||||
h(ctx)
|
||||
}
|
||||
return next.Handle(c)
|
||||
})
|
||||
|
@ -129,13 +129,13 @@ func WrapHandler(h http.Handler) echo.HandlerFunc {
|
||||
}
|
||||
|
||||
// WrapMiddleware wraps `http.Handler` into `echo.MiddlewareFunc`
|
||||
func WrapMiddleware(m http.Handler) echo.MiddlewareFunc {
|
||||
func WrapMiddleware(h http.Handler) echo.MiddlewareFunc {
|
||||
return func(next echo.Handler) echo.Handler {
|
||||
return echo.HandlerFunc(func(c echo.Context) error {
|
||||
w := c.Response().Object().(http.ResponseWriter)
|
||||
r := c.Request().Object().(*http.Request)
|
||||
if !c.Response().Committed() {
|
||||
m.ServeHTTP(w, r)
|
||||
h.ServeHTTP(w, r)
|
||||
}
|
||||
return next.Handle(c)
|
||||
})
|
||||
|
@ -351,12 +351,18 @@ func (r *Router) Find(method, path string, context Context) {
|
||||
// Param node
|
||||
Param:
|
||||
if c = cn.findChildByKind(pkind); c != nil {
|
||||
// Issue #378
|
||||
if len(ctx.pvalues) == n {
|
||||
continue
|
||||
}
|
||||
|
||||
// Save next
|
||||
if cn.label == '/' {
|
||||
nk = akind
|
||||
nn = cn
|
||||
ns = search
|
||||
}
|
||||
|
||||
cn = c
|
||||
i, l := 0, len(search)
|
||||
for ; i < l && search[i] != '/'; i++ {
|
||||
|
@ -311,6 +311,25 @@ func TestRouterTwoParam(t *testing.T) {
|
||||
assert.Equal(t, "1", c.P(1))
|
||||
}
|
||||
|
||||
// Issue #378
|
||||
func TestRouterParamWithSlash(t *testing.T) {
|
||||
e := New()
|
||||
r := e.router
|
||||
|
||||
r.Add(GET, "/a/:b/c/d/:e", HandlerFunc(func(c Context) error {
|
||||
return nil
|
||||
}), e)
|
||||
|
||||
r.Add(GET, "/a/:b/c/:d/:f", HandlerFunc(func(c Context) error {
|
||||
return nil
|
||||
}), e)
|
||||
|
||||
c := NewContext(nil, nil, e)
|
||||
assert.NotPanics(t, func() {
|
||||
r.Find(GET, "/a/1/c/d/2/3", c)
|
||||
})
|
||||
}
|
||||
|
||||
func TestRouterMatchAny(t *testing.T) {
|
||||
e := New()
|
||||
r := e.router
|
||||
|
Loading…
Reference in New Issue
Block a user