From b992021af0773d3931fd67d95b0a57891e862051 Mon Sep 17 00:00:00 2001 From: Laurento Frittella Date: Fri, 3 Jan 2025 15:19:59 +0100 Subject: [PATCH] New custom client that supports Digest auth and makes use of rclone's transport. --- backend/webdav/webdav.go | 7 +------ fs/fshttp/http.go | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/backend/webdav/webdav.go b/backend/webdav/webdav.go index 62f58ed17..b2c884bfe 100644 --- a/backend/webdav/webdav.go +++ b/backend/webdav/webdav.go @@ -40,7 +40,6 @@ import ( "github.com/rclone/rclone/lib/rest" ntlmssp "github.com/Azure/go-ntlmssp" - "github.com/icholy/digest" ) const ( @@ -505,11 +504,7 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e // If available, prefer Digest authentication. if checkForDigestAuth(opt.URL) { fs.Debugf(nil, "using Digest authentication scheme") - client.Transport = &digest.Transport{ - Jar: client.Jar, - Username: opt.User, - Password: opt.Pass, - } + client = fshttp.NewClientWithDigestAuth(ctx, opt.User, opt.Pass) } } diff --git a/fs/fshttp/http.go b/fs/fshttp/http.go index 9d405df1d..52418825e 100644 --- a/fs/fshttp/http.go +++ b/fs/fshttp/http.go @@ -14,6 +14,7 @@ import ( "sync" "time" + "github.com/icholy/digest" "github.com/rclone/rclone/fs" "github.com/rclone/rclone/fs/accounting" "github.com/rclone/rclone/lib/structs" @@ -168,6 +169,27 @@ func NewClientWithUnixSocket(ctx context.Context, path string) *http.Client { }) } +// NewClientWithDigestAuth returns an http.Client that supports the Digest authentication scheme. +func NewClientWithDigestAuth(ctx context.Context, username, password string) *http.Client { + ci := fs.GetConfig(ctx) + + dt := &digest.Transport{ + Username: username, + Password: password, + } + // override the default transport with the custom implementation. + dt.Transport = NewTransport(ctx) + + client := &http.Client{ + Transport: dt, + } + if ci.Cookie { + client.Jar = cookieJar + dt.Jar = cookieJar + } + return client +} + // Transport is our http Transport which wraps an http.Transport // * Sets the User Agent // * Does logging