-
Notifications
You must be signed in to change notification settings - Fork 0
/
aws_middleware.go
33 lines (29 loc) · 1.11 KB
/
aws_middleware.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package main
import (
"context"
"strings"
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/aws/smithy-go/middleware"
"github.com/aws/smithy-go/transport/http"
)
// mergeObjectAttributesHeader manipulates the request client-side before it is
// dispatched, and merges multiple X-Amz-Object-Attributes headers into one
// comma-separated line, working around the bug in MinIO logged in
// https://github.com/minio/minio/issues/20267.
func mergeObjectAttributesHeader(opt *s3.Options) {
opt.APIOptions = append(opt.APIOptions, func(stack *middleware.Stack) error {
return stack.Finalize.Add(middleware.FinalizeMiddlewareFunc(
"mergeObjectAttributesHeaders",
func(ctx context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler) (
out middleware.FinalizeOutput, metadata middleware.Metadata, err error,
) {
const headerKey = `X-Amz-Object-Attributes`
req := in.Request.(*http.Request)
values := req.Header.Values(headerKey)
req.Header.Set(headerKey, strings.Join(values, ","))
in.Request = req
return next.HandleFinalize(ctx, in)
},
), middleware.Before)
})
}