From 4ac5cb07cabe3ceff0050ba7fc20f20022d06aca Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Fri, 3 Nov 2023 11:24:17 +0000 Subject: [PATCH] gcs: fix 400 Bad request errors when using multi-thread copy Before this change, on every Open, we added the userProject parameter to the URL in the object. This meant it grew and grew until Google returned Error 400 (Bad Request) errors when the URL became too long. This fixes the problem by adding the userProject parameter once. See: https://forum.rclone.org/t/endlessly-repeating-userproject-parameter-in-get-to-google-storage-context-canceled-got-http-response-code-400/42652 --- backend/googlecloudstorage/googlecloudstorage.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/googlecloudstorage/googlecloudstorage.go b/backend/googlecloudstorage/googlecloudstorage.go index 5f8458788..1d1bffaee 100644 --- a/backend/googlecloudstorage/googlecloudstorage.go +++ b/backend/googlecloudstorage/googlecloudstorage.go @@ -1310,10 +1310,11 @@ func (o *Object) Storable() bool { // Open an object for read func (o *Object) Open(ctx context.Context, options ...fs.OpenOption) (in io.ReadCloser, err error) { + url := o.url if o.fs.opt.UserProject != "" { - o.url = o.url + "&userProject=" + o.fs.opt.UserProject + url += "&userProject=" + o.fs.opt.UserProject } - req, err := http.NewRequestWithContext(ctx, "GET", o.url, nil) + req, err := http.NewRequestWithContext(ctx, "GET", url, nil) if err != nil { return nil, err }