echo icon indicating copy to clipboard operation
echo copied to clipboard

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

Open mei-rune opened this issue 2 years ago • 2 comments

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

  • [x] Dependencies installed
  • [x] No typos
  • [x] Searched existing issues and docs

mei-rune avatar Apr 30 '22 04:04 mei-rune

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.

aldas avatar Apr 30 '22 05:04 aldas

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

mei-rune avatar Apr 30 '22 06:04 mei-rune