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 cloud.google.com/go/storage v1.39
(googleapis/google-cloud-go#9431).
  • Loading branch information
stanhu committed Feb 29, 2024
1 parent bfbcaa1 commit 2132176
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 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
4 changes: 4 additions & 0 deletions blob/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ 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, the driver should attempt to disable any automatic
// content-type detection that the provider applies on writes with an
// empty ContentType.
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

0 comments on commit 2132176

Please sign in to comment.