From 8aef1de695268ba874da08d4016bb3cd9eca988b Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Tue, 6 Aug 2024 11:04:40 +0100 Subject: [PATCH] s3: fix Cloudflare R2 integration tests after SDKv2 update #4989 Cloudflare will normally automatically decompress files with `Content-Encoding: gzip` when downloaded. This is not what AWS S3 does and it breaks the integration tests. This fudges the integration tests to upload the test file with `Cache-Control: no-transform` on Cloudflare R2 and puts a note in the docs about this problem. --- backend/s3/s3_internal_test.go | 10 ++++++++++ docs/content/s3.md | 9 ++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/backend/s3/s3_internal_test.go b/backend/s3/s3_internal_test.go index 5b68fdb08..86e23e436 100644 --- a/backend/s3/s3_internal_test.go +++ b/backend/s3/s3_internal_test.go @@ -60,6 +60,16 @@ func (f *Fs) InternalTestMetadata(t *testing.T) { // "tier" - read only // "btime" - read only } + // Cloudflare insists on decompressing `Content-Encoding: gzip` unless + // `Cache-Control: no-transform` is supplied. This is a deviation from + // AWS but we fudge the tests here rather than breaking peoples + // expectations of what Cloudflare does. + // + // This can always be overridden by using + // `--header-upload "Cache-Control: no-transform"` + if f.opt.Provider == "Cloudflare" { + metadata["cache-control"] = "no-transform" + } obj := fstests.PutTestContentsMetadata(ctx, t, f, &item, true, contents, true, "text/html", metadata) defer func() { assert.NoError(t, obj.Remove(ctx)) diff --git a/docs/content/s3.md b/docs/content/s3.md index 7be465320..6f9aef1b9 100644 --- a/docs/content/s3.md +++ b/docs/content/s3.md @@ -2388,7 +2388,14 @@ acl = private Now run `rclone lsf r2:` to see your buckets and `rclone lsf r2:bucket` to look within a bucket. -For R2 tokens with the "Object Read & Write" permission, you may also need to add `no_check_bucket = true` for object uploads to work correctly. +For R2 tokens with the "Object Read & Write" permission, you may also +need to add `no_check_bucket = true` for object uploads to work +correctly. + +Note that Cloudflare decompresses files uploaded with +`Content-Encoding: gzip` by default which is a deviation from what AWS +does. If this is causing a problem then upload the files with +`--header-upload "Cache-Control: no-transform"` ### Dreamhost