Description
The GET Bucket cors API allows the bucket owner to s et the CORS for a bucket. (cors is a W3C standard, the full name is Cross-origin resource sharing). By default, the owner of the bucket has the permission to access the API, and can grant permissions to other users.
Request
Request Example
GET /?cors HTTP/1.1
Host: <BucketName-APPID>.<Endpoint>
Date: GMT Date
Authorization: Auth String
Note:
Authorization: Auth String (See Request Signature for details.)
Request Header
Common Headers
This request uses common request headers. For details, see Common Request Headers.
Non-common Headers
This request has no special request header information.
Request Body
The request body of this request is empty.
Response
Response Headers
Common Response Headers
This response contains common response headers. For details, see Common Response Headers.
Special Response Headers
There are no special response headers for this response operation.
Response Body
The CORS has been configured successfully.
<?xml version="1.0" encoding="UTF-8" ?>
<CORSConfiguration>
<CORSRule>
<ID>bucketid</ID>
<AllowedOrigin>http://www.test.com</AllowedOrigin>
<AllowedMethod>PUT</AllowedMethod>
<AllowedHeader>x-cos-meta-test</AllowedHeader>
<ExposeHeader>x-cos-meta-test1</ExposeHeader>
<MaxAgeSeconds>500</MaxAgeSeconds>
</CORSRule>
</CORSConfiguration>
The data are described as follows:
| Node Name (Keyword) | Parent Node | Description | Type | Required |
|---|---|---|---|---|
| CORSConfiguration | No | All information about CORS rule. You can configure up to 100 CORSRule. | Container | Yes |
Content of CORSConfiguration:
| Node Name (Keyword) | Parent Node | Description | Type | Required |
|---|---|---|---|---|
| CORSRule | CORSConfiguration | All information about CORS rule. You can configure up to 100 CORSRule. | Container | Yes |
Content of CORSRule:
| Node Name (Keyword) | Parent Node | Description | Type | Required |
|---|---|---|---|---|
| ID | CORSConfiguration.CORSRule | ID of the CORSRule, not required. | string | Yes |
| AllowedOrigin | CORSConfiguration.CORSRule | Allowed access source. The wildcard * is supported. Format: protocol://domain name[:port], such as http://www.test.com. |
strings | Yes |
| AllowedMethod | CORSConfiguration.CORSRule | Allowed HTTP operations. Enumerated values: GET, PUT, HEAD, POST, and DELETE | strings | Yes |
| AllowedHeader | CORSConfiguration.CORSRule | When an OPTIONS request is sent, the browser will let the server know what custom HTTP headers will be used in the actual request. You can set it to * to allow all domains. | strings | Yes |
| MaxAgeSeconds | CORSConfiguration.CORSRule | Validity period of the result obtained by the OPTIONS request. | integer | Yes |
| ExposeHeader | CORSConfiguration.CORSRule | User-defined header information from the server side that the browser can receive. | strings | Yes |
Error Code
This request returns common error responses and error codes. For more information, see Error Codes.
Practical Case
Request
GET /?cors HTTP/1.1
Host: <BucketName-APPID>.<Endpoint>
Date: Wed, 28 Oct 2016 21:32:00 GMT
Authorization: q-sign-algorithm=sha1&q-ak=AKIDxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&q-sign-time=1484815944;32557711944&q-key-time=1484815944;32557711944&q-header-list=host&q-url-param-list=cors&q-signature=a2d28e1b9023d09f9277982775a4b3b705d0e23e
Response
HTTP/1.1 200 OK
Content-Type: application/xml
Content-Length: 345
Connection: keep-alive
Date: Wed, 28 Oct 2016 21:32:00 GMT
x-cos-request-id: NTg4MDdlNGZfNDYyMDRlXzM0YWFfZTBh
<CORSConfiguration>
<CORSRule>
<ID>bucketid</ID>
<AllowedOrigin>http://www.test.com</AllowedOrigin>
<AllowedMethod>PUT</AllowedMethod>
<AllowedHeader>x-cos-meta-test</AllowedHeader>
<ExposeHeader>x-cos-meta-test1</ExposeHeader>
<MaxAgeSeconds>500</MaxAgeSeconds>
</CORSRule>
</CORSConfiguration>