Skip to content

Commit

Permalink
blob/gcsblob: Ensure driver sets Content-Type auto-detection properly
Browse files Browse the repository at this point in the history
google#3371 made it possible to
disable Go Cloud's Content-Type auto-detection via the
`DisableContentTypeDetection` option. However, the Google Cloud
Storage (GCS) driver still performed auto-detection even if this
option were enabled, so it was previously not possible to keep
`Content-Type` blank. This commit adds the
`DisableContentTypeDetection` option to the the driver and passes
along the value to make it possible to keep Content-Type blank in the
GCS object metadata. This enables the use of the
`Response-Content-Type` override in a signed URL.

This commit needs
googleapis/google-cloud-go#9431 to work.
`go.mod` has been updated to use pseudo-version until
cloud.google.com/go/storage v1.39 is available
(googleapis/google-cloud-go#9457).
  • Loading branch information
stanhu committed Feb 23, 2024
1 parent 5ec203b commit 8066870
Show file tree
Hide file tree
Showing 5 changed files with 597 additions and 90 deletions.
17 changes: 9 additions & 8 deletions blob/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -1083,14 +1083,15 @@ func (b *Bucket) NewWriter(ctx context.Context, key string, opts *WriterOptions)
opts = &WriterOptions{}
}
dopts := &driver.WriterOptions{
CacheControl: opts.CacheControl,
ContentDisposition: opts.ContentDisposition,
ContentEncoding: opts.ContentEncoding,
ContentLanguage: opts.ContentLanguage,
ContentMD5: opts.ContentMD5,
BufferSize: opts.BufferSize,
MaxConcurrency: opts.MaxConcurrency,
BeforeWrite: opts.BeforeWrite,
CacheControl: opts.CacheControl,
ContentDisposition: opts.ContentDisposition,
ContentEncoding: opts.ContentEncoding,
ContentLanguage: opts.ContentLanguage,
ContentMD5: opts.ContentMD5,
BufferSize: opts.BufferSize,
MaxConcurrency: opts.MaxConcurrency,
BeforeWrite: opts.BeforeWrite,
DisableContentTypeDetection: opts.DisableContentTypeDetection,
}
if len(opts.Metadata) > 0 {
// Services are inconsistent, but at least some treat keys
Expand Down
6 changes: 6 additions & 0 deletions blob/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ type WriterOptions struct {
// Metadata holds key/value strings to be associated with the blob.
// Keys are guaranteed to be non-empty and lowercased.
Metadata map[string]string
// When true, if ContentType is the empty string, it will stay the empty
// string rather than being inferred from the content.
// Note that while the blob will be written with an empty string ContentType,
// most providers will fill one in during reads, so don't expect an empty
// ContentType if you read the blob back.
DisableContentTypeDetection bool
// BeforeWrite is a callback that must be called exactly once before
// any data is written, unless NewTypedWriter returns an error, in
// which case it should not be called.
Expand Down
1 change: 1 addition & 0 deletions blob/gcsblob/gcsblob.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ func (b *bucket) NewTypedWriter(ctx context.Context, key string, contentType str
w.ChunkSize = bufferSize(opts.BufferSize)
w.Metadata = opts.Metadata
w.MD5 = opts.ContentMD5
w.ForceEmptyContentType = opts.DisableContentTypeDetection
return w
}

Expand Down
60 changes: 34 additions & 26 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ go 1.20
require (
cloud.google.com/go/compute/metadata v0.2.3
cloud.google.com/go/firestore v1.14.0
cloud.google.com/go/iam v1.1.5
cloud.google.com/go/kms v1.15.5
cloud.google.com/go/pubsub v1.33.0
cloud.google.com/go/secretmanager v1.11.4
cloud.google.com/go/storage v1.35.1
cloud.google.com/go/iam v1.1.6
cloud.google.com/go/kms v1.15.7
cloud.google.com/go/pubsub v1.36.1
cloud.google.com/go/secretmanager v1.11.5
cloud.google.com/go/storage v1.38.1-0.20240223003415-067667058c06
contrib.go.opencensus.io/exporter/aws v0.0.0-20230502192102-15967c811cec
contrib.go.opencensus.io/exporter/stackdriver v0.13.14
contrib.go.opencensus.io/integrations/ocsql v0.1.7
Expand All @@ -35,7 +35,7 @@ require (
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.2.0
github.com/Azure/go-amqp v1.0.2
github.com/Azure/go-autorest/autorest/to v0.4.0
github.com/GoogleCloudPlatform/cloudsql-proxy v1.33.14
github.com/GoogleCloudPlatform/cloudsql-proxy v1.33.0
github.com/aws/aws-sdk-go v1.49.0
github.com/aws/aws-sdk-go-v2 v1.24.0
github.com/aws/aws-sdk-go-v2/config v1.26.1
Expand All @@ -53,28 +53,28 @@ require (
github.com/google/go-cmp v0.6.0
github.com/google/go-replayers/grpcreplay v1.1.0
github.com/google/go-replayers/httpreplay v1.2.0
github.com/google/uuid v1.4.0
github.com/google/uuid v1.6.0
github.com/google/wire v0.5.0
github.com/googleapis/gax-go/v2 v2.12.0
github.com/googleapis/gax-go/v2 v2.12.1
github.com/lib/pq v1.10.9
go.opencensus.io v0.24.0
golang.org/x/crypto v0.17.0
golang.org/x/net v0.18.0
golang.org/x/oauth2 v0.14.0
golang.org/x/sync v0.5.0
golang.org/x/crypto v0.19.0
golang.org/x/net v0.21.0
golang.org/x/oauth2 v0.17.0
golang.org/x/sync v0.6.0
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028
google.golang.org/api v0.151.0
google.golang.org/genproto v0.0.0-20231120223509-83a465c0220f
google.golang.org/grpc v1.59.0
google.golang.org/protobuf v1.31.0
google.golang.org/api v0.166.0
google.golang.org/genproto v0.0.0-20240221002015-b0ce06bbee7c
google.golang.org/grpc v1.62.0
google.golang.org/protobuf v1.32.0
)

require (
cloud.google.com/go v0.110.10 // indirect
cloud.google.com/go/compute v1.23.3 // indirect
cloud.google.com/go/longrunning v0.5.4 // indirect
cloud.google.com/go/monitoring v1.16.3 // indirect
cloud.google.com/go/trace v1.10.4 // indirect
cloud.google.com/go v0.112.0 // indirect
cloud.google.com/go/compute v1.24.0 // indirect
cloud.google.com/go/longrunning v0.5.5 // indirect
cloud.google.com/go/monitoring v1.18.0 // indirect
cloud.google.com/go/trace v1.10.5 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/keyvault/internal v0.7.1 // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
Expand All @@ -93,6 +93,9 @@ require (
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.21.5 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.26.5 // indirect
github.com/census-instrumentation/opencensus-proto v0.4.1 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang-jwt/jwt/v5 v5.1.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
Expand All @@ -102,13 +105,18 @@ require (
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
github.com/prometheus/prometheus v0.48.0 // indirect
github.com/prometheus/prometheus v0.40.7 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.48.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.48.0 // indirect
go.opentelemetry.io/otel v1.23.1 // indirect
go.opentelemetry.io/otel/metric v1.23.1 // indirect
go.opentelemetry.io/otel/trace v1.23.1 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.4.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231120223509-83a465c0220f // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240221002015-b0ce06bbee7c // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240221002015-b0ce06bbee7c // indirect
)
Loading

0 comments on commit 8066870

Please sign in to comment.