1
0
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:
Arun Gopalpuri
2020-08-28 12:47:02 -07:00
parent cb84205219
commit 1a6ec73e57
6 changed files with 63 additions and 28 deletions

View File

@ -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
}
}