Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

fs: Allow the http Transport to have an optional filter request function

Nick Craig-Woodfdb01437d812
diff --git a/fs/http.go b/fs/http.go
index a9d0dd2d3..6271b529d 100644
--- a/fs/http.go
+++ b/fs/http.go
@@ -146,7 +146,8 @@ func (ci *ConfigInfo) Client() *http.Client {
// * Does logging
type Transport struct {
*http.Transport
- dump DumpFlags
+ dump DumpFlags
+ filterRequest func(req *http.Request)
}
// NewTransport wraps the http.Transport passed in and logs all
@@ -158,6 +159,11 @@ func NewTransport(transport *http.Transport, dump DumpFlags) *Transport {
}
}
+// SetRequestFilter sets a filter to be used on each request
+func (t *Transport) SetRequestFilter(f func(req *http.Request)) {
+ t.filterRequest = f
+}
+
// A mutex to protect this map
var checkedHostMu sync.RWMutex
@@ -249,6 +255,10 @@ func (t *Transport) RoundTrip(req *http.Request) (resp *http.Response, err error
}
// Force user agent
req.Header.Set("User-Agent", *userAgent)
+ // Filter the request if required
+ if t.filterRequest != nil {
+ t.filterRequest(req)
+ }
// Logf request
if t.dump&(DumpHeaders|DumpBodies|DumpAuth|DumpRequests|DumpResponses) != 0 {
buf, _ := httputil.DumpRequestOut(req, t.dump&(DumpBodies|DumpRequests) != 0)