From ba721bc6a02a9e4e1c164947aeab6efdf9be313c Mon Sep 17 00:00:00 2001 From: Aur0ra <2540313779@qq.com> Date: Mon, 10 Apr 2023 00:08:17 +0800 Subject: [PATCH] perf: change http clone cache key --- core/ahttp/ahttp.go | 9 ++++++--- core/ahttp/ahttpModify.go | 4 +++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/core/ahttp/ahttp.go b/core/ahttp/ahttp.go index b22344b..cfcad14 100644 --- a/core/ahttp/ahttp.go +++ b/core/ahttp/ahttp.go @@ -13,7 +13,7 @@ import ( ) type requestCacheBlock struct { - key string //method-domain-url + key *http.Request //method-domain-url value string } @@ -88,7 +88,10 @@ func RequestClone(src *http.Request) *http.Request { // dump request reqStr := "" for _, c := range cache { - if c != nil && c.key == src.URL.String() { + if c == nil { + break + } + if c.key == src { reqStr = c.value break } @@ -99,7 +102,7 @@ func RequestClone(src *http.Request) *http.Request { if cache[updatePoint] == nil { cache[updatePoint] = &requestCacheBlock{} } - cache[updatePoint].key = src.URL.String() + cache[updatePoint].key = src cache[updatePoint].value = reqStr updatePoint = (updatePoint + 1) % 128 } diff --git a/core/ahttp/ahttpModify.go b/core/ahttp/ahttpModify.go index bab4e4b..9096cf5 100644 --- a/core/ahttp/ahttpModify.go +++ b/core/ahttp/ahttpModify.go @@ -94,6 +94,8 @@ func ModifyURLPathMidPad(Url *url.URL, padding string) { if strings.HasSuffix(Url.Path, "/") { srcPath = strings.TrimRight(srcPath, "/") } + // trim the first separator + srcPath = strings.TrimLeft(srcPath, "/") // split path into fragments splits := strings.Split(srcPath, "/") @@ -108,7 +110,7 @@ func ModifyURLPathMidPad(Url *url.URL, padding string) { newPath = firstPart + "/" + padding + "/" + thirdPart } else { - newPath = padding + "/" + firstPart + newPath = "/" + padding + "/" + firstPart } Url.Path = newPath }