Repository navigation
Description
I've tried quite a few ways of setting the Cache-Control metadata and am unable to do so in a way that is reflected in the object response's Cache-Control header. I feel like I've got to be doing something wrong, as this is probably one of the more common headers to set for objects.
When I try to set it on the file's metadata during upload, it never seems to get set.
bucket.upload(source, {
destination: dest,
gzip: true,
metadata: {
'Vary': 'Accept-Encoding',
'Cache-Control': 'public, max-age=14400'
}
}, done)curl --head call for the file:
HTTP/1.1 200 OK
X-GUploader-UploadID: AEnB2UrsdtueM7WljXcrRXU3NwRCqDJ-kL6_wPze_OeEzPUsa05eC2hzAUDsY6S5mpyPRr79hRD_UlPJ0rqaBVs9WsMDMopMVg
Expires: Tue, 26 Jan 2016 00:18:34 GMT
Date: Mon, 25 Jan 2016 23:18:34 GMT
Cache-Control: public, max-age=3600
Last-Modified: Mon, 25 Jan 2016 23:18:29 GMT
ETag: W/"9072e88dbe39c375e51263697684c9ef"
x-goog-generation: 1453763909213000
x-goog-metageneration: 1
x-goog-stored-content-encoding: gzip
x-goog-stored-content-length: 56043
Content-Type: application/javascript; charset=utf-8
x-goog-hash: crc32c=d9f3Pw==
x-goog-hash: md5=kHLojb45w3XlEmNpdoTJ7w==
x-goog-storage-class: STANDARD
Vary: Accept-Encoding
Server: UploadServer
Alternate-Protocol: 443:quic,p=1
Alt-Svc: quic=":443"; ma=604800; v="30,29,28,27,26,25"
Transfer-Encoding: chunked
I seem to get back the default Cache-Control value here, and when viewing the file in the Google Cloud UI I see:
I then tried calling file.setMetadata() after the upload:
file.setMetadata({
metadata: {
'Cache-Control': 'public, max-age=57600'
}
}, done)... and I get the following:
Notice the same default value for Cache-Control, but the appropriate value for x-goog-meta-Cache-Control.
HTTP/1.1 200 OK
X-GUploader-UploadID: AEnB2Ur-Sisk_qHR767OwpO-hQJwEFyGlkIJ6Tx-XAe0pCCUXWeeu-k38wpImLQnlWvr82p74AjzHO_iuvv-6kWAsP63E_UpCg
Expires: Tue, 26 Jan 2016 00:23:20 GMT
Date: Mon, 25 Jan 2016 23:23:20 GMT
Cache-Control: public, max-age=3600
Last-Modified: Mon, 25 Jan 2016 23:22:40 GMT
ETag: W/"9072e88dbe39c375e51263697684c9ef"
x-goog-generation: 1453764160154000
x-goog-metageneration: 2
x-goog-stored-content-encoding: gzip
x-goog-stored-content-length: 56043
x-goog-meta-Cache-Control: public, max-age=57600
Content-Type: application/javascript; charset=utf-8
x-goog-hash: crc32c=d9f3Pw==
x-goog-hash: md5=kHLojb45w3XlEmNpdoTJ7w==
x-goog-storage-class: STANDARD
Vary: Accept-Encoding
Server: UploadServer
Alternate-Protocol: 443:quic,p=1
Alt-Svc: quic=":443"; ma=604800; v="30,29,28,27,26,25"
Transfer-Encoding: chunked
I've tried in a bucket with default object permissions as readable by public, and with setting the actual acl on the file during upload as readable by public, but see the same results. Any help would be greatly appreciated.


Activity
stephenplusplus commentedon Jan 26, 2016
Thanks for reporting this. I'll play with it and let you know if I can find a solution.
stephenplusplus commentedon Jan 26, 2016
Alright, give this a shot:
bucket.upload(source, { destination: dest, gzip: true, metadata: { - 'Vary': 'Accept-Encoding', - 'Cache-Control': 'public, max-age=14400' + cacheControl: 'public, max-age=14400' } }, done)The
varyheader is defaulted.I'm going to send a PR that will make the connection between
options.metadataand the upstream Storage API's resource definition outlined here: https://cloud.google.com/storage/docs/json_api/v1/objects/insert#request_properties_JSONselfcontained commentedon Jan 26, 2016
Doh, I knew it had to be something silly I was missing. That link to the doc clears up a lot, thanks @stephenplusplus. Worked like a charm once I switched it to
cacheControl. Thanks for the quick response too, much appreciated.stephenplusplus commentedon Jan 26, 2016
No problem. It's our fault for the unclear docs, so thank you for bringing it to our attention!
fix: do not throw error on empty LRO response (#1087)
chore: release 2.24.2 (#1088)
chore: store nodejs build artifacts in placer (#1087)
chore: store nodejs build artifacts in placer (#1087)
feat!: Drop Node 8 support (#1006)
fix: make request batching work again (#1087)