mirror of https://github.com/rclone/rclone.git
New custom client that supports Digest auth and makes use of rclone's transport.
This commit is contained in:
parent
b305ab0c97
commit
b992021af0
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue