Skip to content

Commit fb4bc4c

Browse files
authored
Add anonymous chunked encoding with trailing headers (#2084)
Trailing headers would be ignored on anonymous uploads. Send these as unsigned aws chunked uploads. Requires minio/minio#21095
1 parent efd53f1 commit fb4bc4c

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

Diff for: api.go

+5
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,11 @@ func (c *Client) newRequest(ctx context.Context, method string, metadata request
909909

910910
// For anonymous requests just return.
911911
if signerType.IsAnonymous() {
912+
if len(metadata.trailer) > 0 {
913+
req.Header.Set("X-Amz-Content-Sha256", unsignedPayloadTrailer)
914+
return signer.UnsignedTrailer(*req, metadata.trailer), nil
915+
}
916+
912917
return req, nil
913918
}
914919

Diff for: pkg/signer/request-signature-v4.go

+23
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,29 @@ func signV4(req http.Request, accessKeyID, secretAccessKey, sessionToken, locati
338338
return &req
339339
}
340340

341+
// UnsignedTrailer will do chunked encoding with a custom trailer.
342+
func UnsignedTrailer(req http.Request, trailer http.Header) *http.Request {
343+
if len(trailer) == 0 {
344+
return &req
345+
}
346+
// Initial time.
347+
t := time.Now().UTC()
348+
349+
// Set x-amz-date.
350+
req.Header.Set("X-Amz-Date", t.Format(iso8601DateFormat))
351+
352+
for k := range trailer {
353+
req.Header.Add("X-Amz-Trailer", strings.ToLower(k))
354+
}
355+
356+
req.Header.Set("Content-Encoding", "aws-chunked")
357+
req.Header.Set("x-amz-decoded-content-length", strconv.FormatInt(req.ContentLength, 10))
358+
359+
// Use custom chunked encoding.
360+
req.Trailer = trailer
361+
return StreamingUnsignedV4(&req, "", req.ContentLength, t)
362+
}
363+
341364
// SignV4 sign the request before Do(), in accordance with
342365
// http://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-authenticating-requests.html.
343366
func SignV4(req http.Request, accessKeyID, secretAccessKey, sessionToken, location string) *http.Request {

0 commit comments

Comments
 (0)