Closed
Description
Issue Description
The proxy middleware is not forwarding requests
Expected behaviour
Middleware should be called to forward request to the another echo instance
> GET http://localhost:8081/resource/1
< HTTP 200
> PUT http://localhost:8081/resource/1
< HTTP 200
Actual behaviour
Middleware is not called and I'm getting back a 405 status code (method not allowed)
> GET http://localhost:8081/resource/1
< HTTP 405
> PUT http://localhost:8081/resource/1
< HTTP 200
Steps to reproduce
GET http://localhost:8081/resource/1
Working code to debug
package main
import (
"net/http"
"net/url"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
)
func main() {
// echo instance 1
e1 := echo.New()
g1 := e1.Group("/api")
g1.GET("/resource/:id", func(c echo.Context) error {
return c.NoContent(http.StatusOK)
})
e1url, _ := url.Parse("http://localhost:8080")
// echo instance 2
e2 := echo.New()
g2 := e2.Group("/api")
g2.PUT("/resource/:id", func(c echo.Context) error {
return c.NoContent(http.StatusOK)
})
g2.Use(middleware.Proxy(middleware.NewRoundRobinBalancer([]*middleware.ProxyTarget{
{
URL: e1url, // forward all requests with /api prefix to server running on port 8080 (except PUT /resource/:id)
},
})))
go e1.Start(":8080")
e2.Start(":8081")
}
Activity
aldas commentedon Mar 12, 2021
This is current limitation of Echo router. It finds match for
/resource/:id
route and stops searching for matching path. Then tries to look up method but GET (only PUT is for that path) is not registered and sends 405Unless you want to wait for fix you can work around this problem by using
skipper
method for proxy and registering additionalAny
route on echo that does proxying. ThisAny
will not be called but it will fool router to match and execute proxy middleware.gustavosbarreto commentedon Mar 12, 2021
Is there any future plan to fix this issue?
router should check if method is suitable for matching route and if n…
Fix router not matching param route with trailing slash and implement…