diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-05-20 23:20:40 -0400 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-05-21 00:06:48 -0400 |
commit | 52176f77e06f6ae68bf16dc170e664c71dd1da8c (patch) | |
tree | c1dcd71003643d2dbfdd6895c967cd9f13203818 /lib | |
parent | 49413ff54541637b1309498eccea599566b75890 (diff) |
httpcache: Handle real long URLs
Diffstat (limited to 'lib')
-rw-r--r-- | lib/httpcache/httpcache.go | 8 |
1 files changed, 8 insertions, 0 deletions
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. |