From 5cb7229a16a118b4ebc7efdd98d67ce35de8341b Mon Sep 17 00:00:00 2001 From: Tim Gallant Date: Mon, 10 Feb 2020 01:02:04 -0800 Subject: [PATCH] s3: add support for HTTPOption --- backend/s3/s3.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) 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 {