diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-05-20 23:20:58 -0400 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-05-21 00:06:48 -0400 |
commit | ec711379f461eca4108bcf824f7ad531aa27d8a3 (patch) | |
tree | ac20348b6ad2ebc32651acf992be943888f47dfc /lib | |
parent | 52176f77e06f6ae68bf16dc170e664c71dd1da8c (diff) |
httpcache: Add some hooks
Diffstat (limited to 'lib')
-rw-r--r-- | lib/httpcache/httpcache.go | 12 |
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 { |