1 Star 0 Fork 0

wpkg/chi

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
clean_path.go 652 Bytes
一键复制 编辑 原始数据 按行查看 历史
arvin 提交于 2023-01-08 21:42 +08:00 . sync at Sun 08 Jan 2023 09:42:18 PM CST
package middleware
import (
"net/http"
"path"
"gitee.com/wpkg/chi"
)
// CleanPath middleware will clean out double slash mistakes from a user's request path.
// For example, if a user requests /users//1 or //users////1 will both be treated as: /users/1
func CleanPath(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
rctx := chi.RouteContext(r.Context())
routePath := rctx.RoutePath
if routePath == "" {
if r.URL.RawPath != "" {
routePath = r.URL.RawPath
} else {
routePath = r.URL.Path
}
rctx.RoutePath = path.Clean(routePath)
}
next.ServeHTTP(w, r)
})
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/wpkg/chi.git
git@gitee.com:wpkg/chi.git
wpkg
chi
chi
508c64771aa7

搜索帮助