Skip to content

Commit 3212f60

Browse files
committed
fix s3 multi p2
1 parent d2e862c commit 3212f60

File tree

2 files changed

+54
-23
lines changed

2 files changed

+54
-23
lines changed

go/chat/s3/multi.go

+28-15
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,14 @@ func (b *Bucket) ListMulti(ctx context.Context, prefix, delim string) (multis []
5757
"prefix": {prefix},
5858
"delimiter": {delim},
5959
}
60+
headers := map[string][]string{}
61+
b.addTokenHeader(headers)
6062
for attempt := b.S3.AttemptStrategy.Start(); attempt.Next(); {
6163
req := &request{
62-
method: "GET",
63-
bucket: b.Name,
64-
params: params,
64+
method: "GET",
65+
bucket: b.Name,
66+
params: params,
67+
headers: headers,
6568
}
6669
var resp listMultiResp
6770
err := b.S3.query(ctx, req, &resp)
@@ -165,7 +168,7 @@ func (m *Multi) putPart(ctx context.Context, n int, r io.ReadSeeker, partSize in
165168
"Content-Length": {strconv.FormatInt(partSize, 10)},
166169
"Content-MD5": {md5b64},
167170
}
168-
b.addTokenHeader(headers)
171+
m.Bucket.addTokenHeader(headers)
169172
params := map[string][]string{
170173
"uploadId": {m.UploadID},
171174
"partNumber": {strconv.FormatInt(int64(n), 10)},
@@ -249,13 +252,17 @@ func (m *Multi) ListParts(ctx context.Context) ([]Part, error) {
249252
"uploadId": {m.UploadID},
250253
"max-parts": {strconv.FormatInt(int64(listPartsMax), 10)},
251254
}
255+
headers := map[string][]string{}
256+
m.Bucket.addTokenHeader(headers)
257+
252258
var parts partSlice
253259
for attempt := m.Bucket.S3.AttemptStrategy.Start(); attempt.Next(); {
254260
req := &request{
255-
method: "GET",
256-
bucket: m.Bucket.Name,
257-
path: m.Key,
258-
params: params,
261+
method: "GET",
262+
bucket: m.Bucket.Name,
263+
path: m.Key,
264+
params: params,
265+
headers: headers,
259266
}
260267
var resp listPartsResp
261268
err := m.Bucket.S3.query(ctx, req, &resp)
@@ -385,15 +392,17 @@ func (m *Multi) Complete(ctx context.Context, parts []Part) error {
385392

386393
// Setting Content-Length prevents breakage on DreamObjects
387394
for attempt := m.Bucket.S3.AttemptStrategy.Start(); attempt.Next(); {
395+
headers := map[string][]string{
396+
"Content-Length": {strconv.Itoa(len(data))},
397+
}
398+
m.Bucket.addTokenHeader(headers)
388399
req := &request{
389400
method: "POST",
390401
bucket: m.Bucket.Name,
391402
path: m.Key,
392403
params: params,
393404
payload: bytes.NewReader(data),
394-
headers: map[string][]string{
395-
"Content-Length": {strconv.Itoa(len(data))},
396-
},
405+
headers: headers,
397406
}
398407

399408
resp := &completeResponse{}
@@ -434,12 +443,16 @@ func (m *Multi) Abort(ctx context.Context) error {
434443
params := map[string][]string{
435444
"uploadId": {m.UploadID},
436445
}
446+
headers := map[string][]string{}
447+
m.Bucket.addTokenHeader(headers)
448+
437449
for attempt := m.Bucket.S3.AttemptStrategy.Start(); attempt.Next(); {
438450
req := &request{
439-
method: "DELETE",
440-
bucket: m.Bucket.Name,
441-
path: m.Key,
442-
params: params,
451+
method: "DELETE",
452+
bucket: m.Bucket.Name,
453+
path: m.Key,
454+
params: params,
455+
headers: headers,
443456
}
444457
err := m.Bucket.S3.query(ctx, req, nil)
445458
if shouldRetry(err) && attempt.HasNext() {

go/chat/s3/s3.go

+26-8
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,14 @@ func (b *Bucket) PutBucket(ctx context.Context, perm ACL) error {
225225
//
226226
// See http://goo.gl/GoBrY for details.
227227
func (b *Bucket) DelBucket() (err error) {
228+
headers := map[string][]string{}
229+
b.addTokenHeader(headers)
230+
228231
req := &request{
229-
method: "DELETE",
230-
bucket: b.Name,
231-
path: "/",
232+
method: "DELETE",
233+
bucket: b.Name,
234+
path: "/",
235+
headers: headers,
232236
}
233237
for attempt := b.S3.AttemptStrategy.Start(); attempt.Next(); {
234238
err = b.S3.query(context.Background(), req, nil)
@@ -321,10 +325,14 @@ func (b *Bucket) GetResponseWithHeaders(ctx context.Context, path string, header
321325

322326
// Exists checks whether or not an object exists on an S3 bucket using a HEAD request.
323327
func (b *Bucket) Exists(path string) (exists bool, err error) {
328+
headers := map[string][]string{}
329+
b.addTokenHeader(headers)
330+
324331
req := &request{
325-
method: "HEAD",
326-
bucket: b.Name,
327-
path: path,
332+
method: "HEAD",
333+
bucket: b.Name,
334+
path: path,
335+
headers: headers,
328336
}
329337
err = b.S3.prepare(req)
330338
if err != nil {
@@ -543,6 +551,7 @@ func (b *Bucket) PutBucketSubresource(subresource string, r io.Reader, length in
543551
headers := map[string][]string{
544552
"Content-Length": {strconv.FormatInt(length, 10)},
545553
}
554+
b.addTokenHeader(headers)
546555
req := &request{
547556
path: "/",
548557
method: "PUT",
@@ -559,6 +568,9 @@ func (b *Bucket) PutBucketSubresource(subresource string, r io.Reader, length in
559568
//
560569
// See http://goo.gl/APeTt for details.
561570
func (b *Bucket) Del(ctx context.Context, path string) error {
571+
headers := map[string][]string{}
572+
b.addTokenHeader(headers)
573+
562574
req := &request{
563575
method: "DELETE",
564576
bucket: b.Name,
@@ -598,6 +610,8 @@ func (b *Bucket) DelMulti(objects Delete) error {
598610
"Content-MD5": {base64.StdEncoding.EncodeToString(digest.Sum(nil))},
599611
"Content-Type": {"text/xml"},
600612
}
613+
b.addTokenHeader(headers)
614+
601615
req := &request{
602616
path: "/",
603617
method: "POST",
@@ -705,9 +719,13 @@ func (b *Bucket) List(prefix, delim, marker string, max int) (result *ListResp,
705719
if max != 0 {
706720
params["max-keys"] = []string{strconv.FormatInt(int64(max), 10)}
707721
}
722+
headers := map[string][]string{}
723+
b.addTokenHeader(headers)
724+
708725
req := &request{
709-
bucket: b.Name,
710-
params: params,
726+
bucket: b.Name,
727+
params: params,
728+
headers: headers,
711729
}
712730
result = &ListResp{}
713731
for attempt := b.S3.AttemptStrategy.Start(); attempt.Next(); {

0 commit comments

Comments
 (0)