From c09e9ad32bcbc8c4661876478e068c4988d4bbf7 Mon Sep 17 00:00:00 2001 From: qydysky Date: Mon, 7 Oct 2024 04:17:56 +0800 Subject: [PATCH] 1 --- local.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/local.go b/local.go index cd4991f..2e35bc2 100644 --- a/local.go +++ b/local.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "net/http" + "net/url" "time" _ "unsafe" @@ -29,12 +30,17 @@ func (localDealer) Deal(ctx context.Context, w http.ResponseWriter, r *http.Requ logFormat = "%v %v%v > %v local %v %v %v" ) - url := chosenBack.To + path := chosenBack.To if chosenBack.PathAdd() { - url += r.RequestURI + if s, e := url.PathUnescape(r.URL.Path); e != nil { + logger.Warn(`W:`, fmt.Sprintf(logFormat, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, "BLOCK", e, time.Since(opT))) + return ErrDealReqUri + } else { + path += s + } } - if !pfile.New(url, 0, true).IsExist() { + if !pfile.New(path, 0, true).IsExist() { return ErrReqDoFail } @@ -45,6 +51,6 @@ func (localDealer) Deal(ctx context.Context, w http.ResponseWriter, r *http.Requ logger.Debug(`T:`, fmt.Sprintf(logFormat, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, r.Method, r.RequestURI, time.Since(opT))) - http.ServeFile(w, r.WithContext(ctx), url) + http.ServeFile(w, r.WithContext(ctx), path) return nil } -- 2.39.2