tencent cloud

Feedback

Custom Headers

Last updated: 2024-05-06 09:46:39

    Feature Overview

    An HTTP header (metadata 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 (metadata 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.
    Note:
    For objects of ARCHIVE and DEEP ARCHIVE, custom headers can only be set during upload. Setting custom headers for objects that have already been uploaded is not supported.

    How It Works

    1. Log in to the COS console.
    2. Click Bucket List on the left sidebar.
    3. Locate the bucket where the object resides and click the bucket name.
    4. Click File List on the left sidebar.
    5. Locate the object for which a header is to be customized and click More > Custom Header in the operation column on the right. To customize headers for multiple objects, select multiple objects and click More Actions > Custom Header on the top.
    6. In the pop-up window, select the parameter type of the metadata header to be set, enter the metadata value, and click OK. COS provides the following six types of object HTTP headers for configuration:
    HTTP Header
    Description
    Example
    Content-Type
    MIME information of the file
    image/jpeg
    Cache-Control
    File caching mechanism
    no-cache: Indicates that cache cannot be used directly, but whether the object has been updated must be verified first with the server. If the object has been updated, it indicates that the cache is expired, and the object must be re-downloaded from the server; if the object has not been updated, the cache is not expired, and the local cache will be used.
    max-age=200: Indicates the relative expiration time of the cached content, in seconds.
    Content-Disposition
    Extension of MIME protocol
    inline: Directly previews the content of the file.
    attachment: Downloads to the specified path in the browser with the original filename.
    attachment; filename="FileName": You should download it to the specified path in the browser with a custom filename. FileName defines the name of the file after download, for example, example.jpg. If the attachment name is in Chinese, it needs to be URL encoded, for example, attachment; filename* = UTF-8' '%E4%B8%AD%E6%96%87.txt
    Content-Encoding
    File encoding format
    gzip
    Note: If the Content-Encoding in the header has been modified as gzip, but the file has not been compressed with gzip, a decoding error will occur.
    Expires
    Expiration date of the cache
    Wed, 21 Oct 2015 07:28:00 GMT
    x-cos-meta-[custom suffix]
    User-defined content
    x-cos-meta-via: homepage
    Note: Header names support only hyphens (-), digits, and English letters (a-z). Uppercase letters in English will be converted to lowercase letters; other characters, including underscores (_), are not supported.

    License request example

    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.

    Non-custom HTTP header of objects

    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.cos.ap-beijing.myqcloud.com
    Date: Fri, 10 Apr 2020 09:35:16 GMT
    Authorization: q-sign-algorithm=sha1&q-ak=AKID8A0fBVtYFrNm02oY1g1JQQF0c3JO****&q-sign-time=1586511316;1586518516&q-key-time=1586511316;1586518516&q-header-list=date;host&q-url-param-list=&q-signature=1bd1898e241fb978df336dc68aaef4c0acae****
    Connection: close

    Response

    HTTP/1.1 200 OK
    Content-Type: text/plain
    Access-Control-Allow-Origin: *
    Last-Modified: Fri, 10 Apr 2020 09:35:05 GMT

    Custom HTTP header of objects

    Refer to directions to add the following custom header configuration:
    Parameter
    Value
    Content-Type
    image/jpeg
    Cache-Control
    no-cache
    Content-Disposition
    attachment; filename* = UTF-8' '%E4%B8%AD%E6%96%87.jpeg
    x-cos-meta-md5
    1234
    then the headers returned for new requests will be as follows:

    Request

    GET /exampleobject.txt HTTP/1.1
    Host: examplebucket-1250000000.cos.ap-beijing.myqcloud.com
    Date: Fri, 10 Apr 2020 09:35:16 GMT
    Authorization: q-sign-algorithm=sha1&q-ak=AKID8A0fBVtYFrNm02oY1g1JQQF0c3JO****&q-sign-time=1586511316;1586518516&q-key-time=1586511316;1586518516&q-header-list=date;host&q-url-param-list=&q-signature=1bd1898e241fb978df336dc68aaef4c0acae****
    Connection: close

    Response

    HTTP/1.1 200 OK
    Cache-Control: no-cache
    Content-Type: image/jpeg
    Content-Disposition: attachment; filename* = UTF-8' '%E4%B8%AD%E6%96%87.jpeg
    x-cos-meta-md5: 1234
    Access-Control-Allow-Origin: *
    Last-Modified: Fri, 10 Apr 2020 09:35:05 GMT
    It can be seen that when custom headers are used, the response format of the page can be changed.
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support