From 52176f77e06f6ae68bf16dc170e664c71dd1da8c Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Tue, 20 May 2025 23:20:40 -0400 Subject: httpcache: Handle real long URLs --- lib/httpcache/httpcache.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/httpcache/httpcache.go b/lib/httpcache/httpcache.go index 38cffcb..91a37c2 100644 --- a/lib/httpcache/httpcache.go +++ b/lib/httpcache/httpcache.go @@ -2,6 +2,8 @@ package httpcache import ( "bufio" + hash "crypto/md5" + "encoding/hex" "encoding/json" "errors" "fmt" @@ -68,6 +70,12 @@ func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) { for _, k := range hdrKeys { cacheKey += "|" + url.QueryEscape(k) + ":" + url.QueryEscape(req.Header[k][0]) } + if len(cacheKey) >= 255 { + prefix := cacheKey[:255-(hash.Size*2)] + csum := hash.Sum([]byte(cacheKey)) + suffix := hex.EncodeToString(csum[:]) + cacheKey = prefix + suffix + } cacheFile := filepath.Join(".http-cache", cacheKey) // Check the mem cache. -- cgit v1.2.3-54-g00ecf