Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

s3: add support for HTTPOption

Tim Gallant5cb7229a16a1
diff --git a/backend/s3/s3.go b/backend/s3/s3.go
index 1353fd666..feb8500c1 100644
--- a/backend/s3/s3.go
+++ b/backend/s3/s3.go
@@ -2127,22 +2127,26 @@ func (o *Object) Open(ctx context.Context, options ...fs.OpenOption) (in io.Read
if o.fs.opt.SSECustomerKeyMD5 != "" {
req.SSECustomerKeyMD5 = &o.fs.opt.SSECustomerKeyMD5
}
+ httpReq, resp := o.fs.c.GetObjectRequest(&req)
fs.FixRangeOption(options, o.bytes)
for _, option := range options {
switch option.(type) {
case *fs.RangeOption, *fs.SeekOption:
_, value := option.Header()
req.Range = &value
+ case *fs.HTTPOption:
+ key, value := option.Header()
+ httpReq.HTTPRequest.Header.Add(key, value)
default:
if option.Mandatory() {
fs.Logf(o, "Unsupported mandatory option: %v", option)
}
}
}
- var resp *s3.GetObjectOutput
err = o.fs.pacer.Call(func() (bool, error) {
var err error
- resp, err = o.fs.c.GetObjectWithContext(ctx, &req)
+ httpReq.HTTPRequest = httpReq.HTTPRequest.WithContext(ctx)
+ err = httpReq.Send()
return o.fs.shouldRetry(err)
})
if err, ok := err.(awserr.RequestFailure); ok {
@@ -2449,6 +2453,18 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
httpReq.Header = headers
httpReq.ContentLength = size
+ for _, option := range options {
+ switch option.(type) {
+ case *fs.HTTPOption:
+ key, value := option.Header()
+ httpReq.Header.Add(key, value)
+ default:
+ if option.Mandatory() {
+ fs.Logf(o, "Unsupported mandatory option: %v", option)
+ }
+ }
+ }
+
err = o.fs.pacer.CallNoRetry(func() (bool, error) {
resp, err := o.fs.srv.Do(httpReq)
if err != nil {