mirror of
https://github.com/labstack/echo.git
synced 2025-07-17 01:43:02 +02:00
using url.EscapedPath instead of custom GetPath, rewritePath func added to middleware - used by proxy and rewrite
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
@ -70,12 +71,14 @@ func RewriteWithConfig(config RewriteConfig) echo.MiddlewareFunc {
|
||||
}
|
||||
|
||||
req := c.Request()
|
||||
|
||||
// Rewrite
|
||||
for k, v := range config.rulesRegex {
|
||||
//use req.URL.Path here or else we will have double escaping
|
||||
replacer := captureTokens(k, req.URL.Path)
|
||||
if replacer != nil {
|
||||
req.URL.Path = replacer.Replace(v)
|
||||
if err := rewritePath(replacer, v, req); err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "invalid url")
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user