Skip to content

Commit

Permalink
perf: change http clone cache key
Browse files Browse the repository at this point in the history
  • Loading branch information
Aur0ra-m committed Apr 9, 2023
1 parent fdccd9b commit ba721bc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 6 additions & 3 deletions core/ahttp/ahttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

type requestCacheBlock struct {
key string //method-domain-url
key *http.Request //method-domain-url
value string
}

Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
4 changes: 3 additions & 1 deletion core/ahttp/ahttpModify.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "/")
Expand All @@ -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
}
Expand Down

0 comments on commit ba721bc

Please # to comment.