Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow client to set Accept-Encoding header in object request #795

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,9 @@ type ObjectHandle struct {
acl ACLHandle
gen int64 // a negative value indicates latest
conds *Conditions
encryptionKey []byte // AES-256 key
userProject string // for requester-pays buckets
encryptionKey []byte // AES-256 key
userProject string // for requester-pays buckets
reqHeaders map[string]string // to set custom request headers e.g. "Accept-Encoding"
}

// ACL provides access to the object's access control list.
Expand Down Expand Up @@ -467,6 +468,19 @@ func (o *ObjectHandle) Delete(ctx context.Context) error {
return err
}

// SetRequestHeader sets the request header on the storage object request.
// Use this to set e.g. "Accept-Encoding: gzip" to prevent decompressive
// transcoding from occurring.
//
// Returns the ObjectHandle itself to allow chaining.
func (o *ObjectHandle) SetRequestHeader(header string, value string) *ObjectHandle {
if o.reqHeaders == nil {
o.reqHeaders = make(map[string]string)
}
o.reqHeaders[header] = string
return o
}

// NewReader creates a new Reader to read the contents of the
// object.
// ErrObjectNotExist will be returned if the object is not found.
Expand Down Expand Up @@ -514,6 +528,12 @@ func (o *ObjectHandle) NewRangeReader(ctx context.Context, offset, length int64)
if o.userProject != "" {
req.Header.Set("X-Goog-User-Project", o.userProject)
}
if o.reqHeaders != nil {
// Allow whitelist of headers
if o.reqHeaders["Accept-Encoding"] != "" {
req.Header.Set("Accept-Encoding", o.reqHeaders["Accept-Encoding"])
}
}
if err := setEncryptionHeaders(req.Header, o.encryptionKey, false); err != nil {
return nil, err
}
Expand Down