Skip to content

Issue setting Cache-Control header #1087

Description

@selfcontained

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:

image

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

In the UI:
image

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

  1. stephenplusplus commented on Jan 26, 2016

    @stephenplusplus
    Contributor

    Thanks for reporting this. I'll play with it and let you know if I can find a solution.

  2. added
    api: storageIssues related to the Cloud Storage API.
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    on Jan 26, 2016
  3. stephenplusplus commented on Jan 26, 2016

    @stephenplusplus
    Contributor

    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 vary header is defaulted.

    I'm going to send a PR that will make the connection between options.metadata and the upstream Storage API's resource definition outlined here: https://cloud.google.com/storage/docs/json_api/v1/objects/insert#request_properties_JSON

  4. added
    type: questionRequest for information or clarification. Not an issue.
    and removed
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    on Jan 26, 2016
  5. selfcontained commented on Jan 26, 2016

    @selfcontained
    Author

    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.

  6. stephenplusplus commented on Jan 26, 2016

    @stephenplusplus
    Contributor

    No problem. It's our fault for the unclear docs, so thank you for bringing it to our attention!

  7. added a commit that references this issue on Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api: storageIssues related to the Cloud Storage API.type: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions