Skip to content

Commit 9d63bd0

Browse files
committed
fix global cacheKey
1 parent 1ee727e commit 9d63bd0

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

pkg/http/cache.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,21 @@ func cloneHeaders(src http.Header) http.Header {
9494
}
9595

9696
func (h handler) getCacheKey(req *http.Request) string {
97+
hash := sha256.New()
98+
hash.Write([]byte(req.Method))
99+
hash.Write([]byte(":"))
100+
hash.Write([]byte(req.URL.Path))
101+
97102
// Check for global cache keys first
98103
for pattern, globalKey := range h.cfg.GlobalCacheKeys {
99104
if strings.HasPrefix(req.URL.Path, pattern) {
100-
return globalKey
105+
hash.Write([]byte(":"))
106+
hash.Write([]byte(globalKey))
107+
108+
return fmt.Sprintf("%x", hash.Sum(nil))
101109
}
102110
}
103111

104-
hash := sha256.New()
105-
hash.Write([]byte(req.Method))
106-
hash.Write([]byte(":"))
107-
hash.Write([]byte(req.URL.Path))
108-
109112
if h.cfg.ShouldHashQuery {
110113
query := req.URL.Query()
111114
keys := make([]string, 0, len(query))

0 commit comments

Comments
 (0)