Currently as far as I'm aware, the storage client does not support setting cache control fields, neither during creation, not by modifying object attributes. Since cache control cannot be set globally on a bucket, only individually on objects, this is an essential feature missing.
Cache control is settable via the object attributes metadata field.
w := storage.NewWriter(ctx, bucket, object)
w.Metadata = map[string]string{
"Cache-Control": "private, max-age=0, no-transform",
}
Ah, so that's where it's hidden. Thanks for the pointer.
Doesn't work :P GCS sets the metadata into a nested set of headers, and doesn't use it directly as the response header (essentially getting it ignored).
I.e. using the above code (slightly modified) returns an object with these headers (I'm playing with the expiration now):
Cache-Control:public, max-age=3600
x-goog-meta-Cache-Control:public, max-age=35
Edit: just to make it full:
out := storage.NewWriter(ctx, bucket, name)
out.ContentEncoding = "gzip"
out.ContentType = "application/json"
out.Metadata = map[string]string{
"Cache-Control": "public, max-age=35",
}
// ...
Snap, I was able to use the metadata fields for the same purpose, seems to be broken now.
Most helpful comment
Doesn't work :P GCS sets the metadata into a nested set of headers, and doesn't use it directly as the response header (essentially getting it ignored).
I.e. using the above code (slightly modified) returns an object with these headers (I'm playing with the expiration now):
Edit: just to make it full: