From 7c98ecd3ab9390062103246730f0908dc1b8183e Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Thu, 23 Apr 2020 15:48:30 +0100 Subject: [PATCH] putio: make downloading files use the rclone http Client This fixes `--download-header` and these transactions being missed from `--dump bodies` or `--tpslimit` --- backend/putio/fs.go | 8 ++++++-- backend/putio/object.go | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/backend/putio/fs.go b/backend/putio/fs.go index 37800e411..6003007ad 100644 --- a/backend/putio/fs.go +++ b/backend/putio/fs.go @@ -18,6 +18,7 @@ import ( "github.com/rclone/rclone/fs" "github.com/rclone/rclone/fs/config/configmap" "github.com/rclone/rclone/fs/config/configstruct" + "github.com/rclone/rclone/fs/fshttp" "github.com/rclone/rclone/fs/hash" "github.com/rclone/rclone/lib/dircache" "github.com/rclone/rclone/lib/oauthutil" @@ -34,7 +35,8 @@ type Fs struct { client *putio.Client // client for making API calls to Put.io pacer *fs.Pacer // To pace the API calls dirCache *dircache.DirCache // Map of directory path to directory id - oAuthClient *http.Client + httpClient *http.Client // base http client + oAuthClient *http.Client // http client with oauth Authorization } // ------------------------------------------------------------ @@ -68,7 +70,8 @@ func NewFs(name, root string, m configmap.Mapper) (f fs.Fs, err error) { if err != nil { return nil, err } - oAuthClient, _, err := oauthutil.NewClient(name, m, putioConfig) + httpClient := fshttp.NewClient(fs.Config) + oAuthClient, _, err := oauthutil.NewClientWithBaseClient(name, m, putioConfig, httpClient) if err != nil { return nil, errors.Wrap(err, "failed to configure putio") } @@ -78,6 +81,7 @@ func NewFs(name, root string, m configmap.Mapper) (f fs.Fs, err error) { opt: *opt, pacer: fs.NewPacer(pacer.NewDefault(pacer.MinSleep(minSleep), pacer.MaxSleep(maxSleep), pacer.DecayConstant(decayConstant))), client: putio.NewClient(oAuthClient), + httpClient: httpClient, oAuthClient: oAuthClient, } p.features = (&fs.Features{ diff --git a/backend/putio/object.go b/backend/putio/object.go index fb6efb220..27723532b 100644 --- a/backend/putio/object.go +++ b/backend/putio/object.go @@ -241,7 +241,7 @@ func (o *Object) Open(ctx context.Context, options ...fs.OpenOption) (in io.Read req.Header.Set(header, value) } // fs.Debugf(o, "opening file: id=%d", o.file.ID) - resp, err = http.DefaultClient.Do(req) + resp, err = o.fs.httpClient.Do(req) return shouldRetry(err) }) if perr, ok := err.(*putio.ErrorResponse); ok && perr.Response.StatusCode >= 400 && perr.Response.StatusCode <= 499 {