labstack / echo

High performance, minimalist Go web framework
https://echo.labstack.com
MIT License
29.84k stars 2.23k forks source link

Can don't change req.RequestURI in middleware.RemoveTrailingSlash()? #2167

Open mei-rune opened 2 years ago

mei-rune commented 2 years ago

Issue Description

Can don't change req.RequestURI in middleware.RemoveTrailingSlash()?

My app has a variable url prefix, the url prefix can change by config file. So I add e.Pre(middleware.RemoveTrailingSlash())

my code is:

   e.Pre(func(next echo.HandlerFunc) echo.HandlerFunc {
        return func(c echo.Context) error {
            req := c.Request()
            url := req.URL
            url.Path = strings.TrimPrefix(url.Path, "/myprefix")
            return next(c)
               }
  })
  e.Pre(middleware.RemoveTrailingSlash())

  // xxxx

   e.Get("/hello", func(c echo.Context) error {
         uri := c.Request().RequestURI

         // uri is /hello,want /myprefix/hello

   })

but I add middleware.RemoveTrailingSlash(), and cannot get raw RequestURI in my codes.

Can fix it https://github.com/labstack/echo/blob/master/middleware/slash.go#L63 https://github.com/labstack/echo/blob/master/middleware/slash.go#L67

Checklist

aldas commented 2 years ago

Hi @runner-mei , this may be controversial advice but you can copy the RemoveTrailingSlash middleware code and create you own middleware out of it and strip/change everything you need.

mei-rune commented 2 years ago

@aldas add a option to control change or no change?