fix: service.Static() URL decoding bug

This commit is contained in:
AI Engineer 2026-06-05 21:15:04 +08:00
parent 94a4be81ec
commit 582de60053
3 changed files with 9 additions and 1 deletions

View File

@ -1,5 +1,10 @@
# CHANGELOG - go/service # CHANGELOG - go/service
## v1.5.10 (2026-06-05)
- **修复: Static 服务 URL 解码**:
- 修复了 \`service.Static()\` 在处理包含空格或特殊字符(如 \`%20\`)的请求路径时,因未解码导致文件匹配失败的问题。
- 在路由匹配阶段提前进行 URL Path 解码,提升整体路径匹配的健壮性。
## v1.5.9 (2026-06-05) ## v1.5.9 (2026-06-05)
- **优化: 低代码环境深度对齐**: - **优化: 低代码环境深度对齐**:
- **JS 友好型 Header**: 引入 \`service.Header\` 包装类,提供大小写不敏感的 \`Get/Set/Add/Del\` 方法,提升脚本开发体验。 - **JS 友好型 Header**: 引入 \`service.Header\` 包装类,提供大小写不敏感的 \`Get/Set/Add/Del\` 方法,提升脚本开发体验。

View File

@ -7,6 +7,7 @@ import (
"apigo.cc/go/timer" "apigo.cc/go/timer"
"io" "io"
"net/http" "net/http"
"net/url"
"reflect" "reflect"
"runtime/debug" "runtime/debug"
"strings" "strings"
@ -148,7 +149,7 @@ func (rh *RouteHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
// 3. 路由匹配 // 3. 路由匹配
path := r.URL.Path path, _ := url.PathUnescape(r.URL.Path)
host := r.Host host := r.Host
// 处理静态文件 // 处理静态文件

View File

@ -5,6 +5,7 @@ import (
"apigo.cc/go/log" "apigo.cc/go/log"
"mime" "mime"
"net/http" "net/http"
"net/url"
"path/filepath" "path/filepath"
"strings" "strings"
"time" "time"
@ -76,6 +77,7 @@ func (ws *webServer) ReplaceStatics(host string, config map[string]string) {
} }
func (ws *webServer) getStaticFilePath(requestPath, host string) string { func (ws *webServer) getStaticFilePath(requestPath, host string) string {
requestPath, _ = url.PathUnescape(requestPath)
ws.staticsByHostLock.RLock() ws.staticsByHostLock.RLock()
defer ws.staticsByHostLock.RUnlock() defer ws.staticsByHostLock.RUnlock()