diff --git a/CHANGELOG.md b/CHANGELOG.md index 2aa8118..7ceea23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # CHANGELOG - go/service +## v1.5.10 (2026-06-05) +- **修复: Static 服务 URL 解码**: + - 修复了 \`service.Static()\` 在处理包含空格或特殊字符(如 \`%20\`)的请求路径时,因未解码导致文件匹配失败的问题。 + - 在路由匹配阶段提前进行 URL Path 解码,提升整体路径匹配的健壮性。 + ## v1.5.9 (2026-06-05) - **优化: 低代码环境深度对齐**: - **JS 友好型 Header**: 引入 \`service.Header\` 包装类,提供大小写不敏感的 \`Get/Set/Add/Del\` 方法,提升脚本开发体验。 diff --git a/handler.go b/handler.go index 040a23f..abdcc10 100644 --- a/handler.go +++ b/handler.go @@ -7,6 +7,7 @@ import ( "apigo.cc/go/timer" "io" "net/http" + "net/url" "reflect" "runtime/debug" "strings" @@ -148,7 +149,7 @@ func (rh *RouteHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } // 3. 路由匹配 - path := r.URL.Path + path, _ := url.PathUnescape(r.URL.Path) host := r.Host // 处理静态文件 diff --git a/static.go b/static.go index c9a708b..f4f59f5 100644 --- a/static.go +++ b/static.go @@ -5,6 +5,7 @@ import ( "apigo.cc/go/log" "mime" "net/http" + "net/url" "path/filepath" "strings" "time" @@ -76,6 +77,7 @@ func (ws *webServer) ReplaceStatics(host string, config map[string]string) { } func (ws *webServer) getStaticFilePath(requestPath, host string) string { + requestPath, _ = url.PathUnescape(requestPath) ws.staticsByHostLock.RLock() defer ws.staticsByHostLock.RUnlock()