Custom Headers

Last updated: 2020-05-12 13:38:32

    Overview

    The HTTP header of an object is a string sent by the server over HTTP protocol before it sends HTML data to browser. By modifying the HTTP header, you can change the response form of the page or communicate configuration information, such as modifying the caching time. Modifying an object's HTTP header does not modify the object itself.

    For example, if the Content-Encoding in Header is modified to gzip, but the file itself has not been compressed to .gz file in advance, a decoding error will occur.

    Note that archived objects do not support custom headers.

    Directions

    1. Log in to the COS Console, and then select the Bucket List in the left pane to go to the Bucket List page. Click the bucket of the object to enter the bucket.
    2. Locate the object for which you want to set headers, and click Details on the right.
    3. Go to the Custom Headers section, and click Add Header. Select a parameter type (enter custom content in the custom field), and enter a value. COS provides the following 6 HTTP headers for objects. Once the configuration is complete, click Save.

    HTTP Header Remarks Example
    Content-Type MIME information of file image/jpeg
    Cache-Control File caching mechanism no-cache;max-age=200
    Content-Disposition Extension with a MIME type 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 content] Custom content x-cos-meta-via: homepage
    4. If you need to add custom headers for more than one object, you can select the objects, and click **Custom Header** under **More Actions**.

    Samples

    Under APPID 1250000000, a bucket named " example" is created. The object exampleobject.txt is uploaded under the bucket root directory.

    If you do not customize the HTTP header for the object, the browser or client will get the following Object headers during download:

    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 

    Add the following configurations:

    When you send a request again, the browser or the client will get the following object headers:

    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