1
0
mirror of https://github.com/labstack/echo.git synced 2025-11-27 22:38:25 +02:00

extend proxy middleware. closes #1202 (#1203)

* extend proxy middleware. closes #1202
This commit is contained in:
Artyom Turkin
2018-10-09 09:43:39 +06:00
committed by Vishal Rana
parent af5c97715f
commit fcdf096c2c
2 changed files with 27 additions and 5 deletions

View File

@@ -124,4 +124,19 @@ func TestProxy(t *testing.T) {
req.URL.Path = "/users/jack/orders/1"
e.ServeHTTP(rec, req)
assert.Equal(t, "/user/jack/order/1", req.URL.Path)
// ProxyTarget is set in context
contextObserver := func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) (err error) {
next(c)
assert.Contains(t, targets, c.Get("target"), "target is not set in context")
return nil
}
}
rrb1 := NewRoundRobinBalancer(targets)
e = echo.New()
e.Use(contextObserver)
e.Use(Proxy(rrb1))
rec = newCloseNotifyRecorder()
e.ServeHTTP(rec, req)
}