summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2025-05-20 23:20:58 -0400
committerLuke T. Shumaker <lukeshu@lukeshu.com>2025-05-21 00:06:48 -0400
commitec711379f461eca4108bcf824f7ad531aa27d8a3 (patch)
treeac20348b6ad2ebc32651acf992be943888f47dfc
parent52176f77e06f6ae68bf16dc170e664c71dd1da8c (diff)
httpcache: Add some hooks
-rw-r--r--lib/httpcache/httpcache.go12
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/httpcache/httpcache.go b/lib/httpcache/httpcache.go
index 91a37c2..b2cc7fe 100644
--- a/lib/httpcache/httpcache.go
+++ b/lib/httpcache/httpcache.go
@@ -16,7 +16,11 @@ import (
"strings"
)
-var UserAgent string
+var (
+ UserAgent string
+ ModifyResponse func(url string, entry CacheEntry, resp *http.Response) *http.Response
+ CheckRedirect func(req *http.Request, via []*http.Request) error
+)
type CacheEntry string
@@ -122,6 +126,9 @@ end:
if err != nil {
panic(fmt.Errorf("invalid cache entry: %v", err))
}
+ if ModifyResponse != nil {
+ ret_resp = ModifyResponse(u, entry, ret_resp)
+ }
case strings.HasPrefix(string(entry), "CLIENT/"):
ret_err = errors.New(string(entry)[len("CLIENT/"):])
default:
@@ -150,7 +157,8 @@ func Get(u string, hdr map[string]string) (string, error) {
req.Header.Add(k, v)
}
client := &http.Client{
- Transport: &transport{},
+ Transport: &transport{},
+ CheckRedirect: CheckRedirect,
}
resp, err := client.Do(req)
if err != nil {