Custom Headers

Last updated: 2020-10-10 10:27:36

    Overview

    An HTTP header of an object is a string sent by the server over HTTP before it sends HTML data to the browser. By modifying HTTP headers, you can modify how the webpage responds as well as certain configurations, such as caching time. Modifying an object's HTTP headers does not modify the object itself.

    For example, if the Content-Encoding header is modified to gzip, but the file itself was not compressed using gzip, a decoding error will occur.

    Note:

    Note that custom headers are not supported for archived objects.

    Directions

    1. Log in to the COS Console and click Bucket List on the left sidebar. Click the specific bucket and enter the bucket details page.
    2. In this example, select a single object that you want to customize under the File List tab, and go to More Actions > Custom Header under Operation to add custom headers. You can also select multiple objects and add custom headers to all of them by going to More Actions > Custom Header** at the top.
    3. In the pop-up window, click Add Header. Select a parameter type, and enter a value for it. COS provides six HTTP headers to choose from. Once the configuration is complete, click OK.
      HTTP Header Description Example
      Content-Type MIME information of the file image/jpeg
      Cache-Control File caching mechanism no-cache;max-age=200
      Content-Disposition MIME type extension attachment;filename="fname.ext"
      Content-Encoding File encoding format UTF-8
      Expires Controls the expiration date of cache Wed, 21 Oct 2015 07:28:00 GMT
      x-cos-meta-[custom suffix] User-defined header x-cos-meta-via: homepage

    Examples

    Assume that a bucket named "examplebucket-1250000000" was created under account APPID 1250000000, and an object “exampleobject.txt” was uploaded to the bucket’s root directory.

    The sample below shows the headers returned for a request to download this object through a browser or client if no custom HTTP headers are specified.

    Request

    GET /exampleobject.txt HTTP/1.1
    Host: examplebucket-1250000000.file.myqcloud.com
    Accept: */*

    Response

    HTTP/1.1 200 OK
    Content-Language:zh-CN
    Content-Type: text/plain
    Content-Disposition: attachment; filename*="UTF-8''exampleobject.txt"
    Access-Control-Allow-Origin: *
    Last-Modified: Tue, 11 Jul 2017 15:30:35 GMT 

    If you add custom headers as follows:

    then the headers returned for new requests will be as follows:

    Request

    GET /exampleobject.txt HTTP/1.1
    Host: examplebucket-1250000000.file.myqcloud.com
    Accept: */*

    Response

    HTTP/1.1 200 OK
    Content-Language:zh-CN
    Cache-Control: no-cache
    Content-Type: image/jpeg
    Content-Disposition: attachment; filename*="abc.txt"
    x-cos-meta-md5: 1234
    Access-Control-Allow-Origin: *
    Last-Modified: Tue, 11 Jul 2017 15:30:35 GMT

    Was this page helpful?

    Was this page helpful?

    • Not at all
    • Not very helpful
    • Somewhat helpful
    • Very helpful
    • Extremely helpful
    Send Feedback
    Help