Skip to content

Commit fba1762

Browse files
authored
Disable chunk encoding for put requests to Google Cloud Storage (#167)
* Set DisableContentSha256=true for Put() requests to Google * Move putObjectOptions to s3 Store struct
1 parent 754ef4a commit fba1762

File tree

1 file changed

+19
-6
lines changed
  • store/precomputed_key/s3

1 file changed

+19
-6
lines changed

store/precomputed_key/s3/s3.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"encoding/hex"
77
"errors"
88
"io"
9+
"net/url"
910
"path"
1011
"time"
1112

@@ -14,6 +15,7 @@ import (
1415
"github.com/minio/minio-go/v7"
1516

1617
"github.com/minio/minio-go/v7/pkg/credentials"
18+
"github.com/minio/minio-go/v7/pkg/s3utils"
1719
)
1820

1921
const (
@@ -50,12 +52,22 @@ type Config struct {
5052
}
5153

5254
type Store struct {
53-
cfg Config
54-
client *minio.Client
55-
stats *store.Stats
55+
cfg Config
56+
client *minio.Client
57+
putObjectOptions minio.PutObjectOptions
58+
stats *store.Stats
5659
}
5760

5861
func NewS3(cfg Config) (*Store, error) {
62+
endpointURL, err := url.Parse(cfg.Endpoint)
63+
if err != nil {
64+
return nil, err
65+
}
66+
putObjectOptions := minio.PutObjectOptions{}
67+
if s3utils.IsGoogleEndpoint(*endpointURL) {
68+
putObjectOptions.DisableContentSha256 = true // Avoid chunk signatures on GCS: https://github.com/minio/minio-go/issues/1922
69+
}
70+
5971
client, err := minio.New(cfg.Endpoint, &minio.Options{
6072
Creds: creds(cfg),
6173
Secure: cfg.EnableTLS,
@@ -65,8 +77,9 @@ func NewS3(cfg Config) (*Store, error) {
6577
}
6678

6779
return &Store{
68-
cfg: cfg,
69-
client: client,
80+
cfg: cfg,
81+
client: client,
82+
putObjectOptions: putObjectOptions,
7083
stats: &store.Stats{
7184
Entries: 0,
7285
Reads: 0,
@@ -97,7 +110,7 @@ func (s *Store) Get(ctx context.Context, key []byte) ([]byte, error) {
97110
}
98111

99112
func (s *Store) Put(ctx context.Context, key []byte, value []byte) error {
100-
_, err := s.client.PutObject(ctx, s.cfg.Bucket, path.Join(s.cfg.Path, hex.EncodeToString(key)), bytes.NewReader(value), int64(len(value)), minio.PutObjectOptions{})
113+
_, err := s.client.PutObject(ctx, s.cfg.Bucket, path.Join(s.cfg.Path, hex.EncodeToString(key)), bytes.NewReader(value), int64(len(value)), s.putObjectOptions)
101114
if err != nil {
102115
return err
103116
}

0 commit comments

Comments
 (0)