mirror of
https://github.com/labstack/echo.git
synced 2025-11-27 22:38:25 +02:00
* extend proxy middleware. closes #1202
This commit is contained in:
committed by
Vishal Rana
parent
af5c97715f
commit
fcdf096c2c
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user