Custom Domain

Last updated: 2020-03-20 12:52:58

PDF

Note

This document provides an overview of API for custom domain names and sample SDK code.

API Operation name pedagogical operation
PUT Bucket domain Set up a custom domain name Set Bucket's custom domain name information
GET Bucket domain Query custom domain name Query Bucket's custom domain name information

Set up a custom domain name

Function description

PUT Bucket domain is used to configure a custom domain name for Bucket.

Method prototype

cos_status_t *cos_put_bucket_domain(const cos_request_options_t *options,
                                      const cos_string_t *bucket,
                                      cos_domain_params_t *domain_params,
                                      cos_table_t **resp_header);

Request Sample

cos_pool_t *pool = NULL;
int is_cname = 0;
cos_status_t *status = NULL;
cos_request_options_t *options = NULL;
cos_domain_params_t  *domain_params = NULL;
cos_domain_params_t  *domain_result = NULL;
cos_table_t *resp_headers = NULL;
cos_string_t bucket;

cos_pool_create(&pool, NULL);

options = cos_request_options_create(pool);
options->config = cos_config_create(options->pool);
cos_str_set(&options->config->endpoint, TEST_COS_ENDPOINT);
cos_str_set(&options->config->access_key_id, TEST_ACCESS_KEY_ID);
cos_str_set(&options->config->access_key_secret, TEST_ACCESS_KEY_SECRET);
cos_str_set(&options->config->appid, TEST_APPID);
options->config->is_cname = is_cname;
options->ctl = cos_http_controller_create(options->pool, 0);
cos_str_set(&bucket, TEST_BUCKET_NAME);

domain_params = cos_create_domain_params(options->pool);
cos_str_set(&domain_params->status, "ENABLED");
cos_str_set(&domain_params->name, "www.exmaple.com");
cos_str_set(&domain_params->type, "REST");
cos_str_set(&domain_params->forced_replacement, "CNAME");

status = cos_put_bucket_domain(options, &bucket, domain_params, &resp_headers);
log_status(status);

cos_pool_destroy(pool);

Parameter description

Parameter name Description Type
OPTIONS COS request options Struct
Bucket Set the custom domain name Bucket in BucketName-APPID format. For more information, please see Naming convention String
Domain_params Bucket Custom Domain name configuration Information Struct
Status Domain name Activate / deactivate status, valid value ENABLED/DISABLED String
Name User's custom domain name. Valid values: letters, numbers, dots String
Type Bound real server type, valid value REST/WEBSITE String
Forced_replacement Replace the existing configuration with a valid value of CNAME/TXT. Enter forcefully verifies the ownership of the domain name, and then deliver configures it. String
Resp_headers Returns the header field of the HTTP response message Struct

Return result description

Returned Result Description Type
Code Error Codes Int
Error_code Error code content String
Error_msg Error code description String
Req_id Request message ID String

Returns the error code description

Some common special errors that may occur in this request are as follows:

Status Code Description
HTTP 409 Conflict The domain name record already exists and no mandatory overwrite is set in the request. Or the domain name record does not exist and a forced overwrite is set in the request
HTTP 451 Unavailable For Legal Reasons The domain name is a domain name within China, and there is no ICP filing.

Query custom domain name

Function description

GET Bucket domain is used to query Bucket's custom domain name information.

Method prototype

cos_status_t *cos_get_bucket_domain(const cos_request_options_t *options,
                                      const cos_string_t *bucket,
                                      cos_domain_params_t *domain_params,
                                      cos_table_t **resp_header);

Request Sample

cos_pool_t *pool = NULL;
int is_cname = 0;
cos_status_t *status = NULL;
cos_request_options_t *options = NULL;
cos_domain_params_t  *domain_params = NULL;
cos_domain_params_t  *domain_result = NULL;
cos_table_t *resp_headers = NULL;
cos_string_t bucket;

cos_pool_create(&pool, NULL);

options = cos_request_options_create(pool);
options->config = cos_config_create(options->pool);
cos_str_set(&options->config->endpoint, TEST_COS_ENDPOINT);
cos_str_set(&options->config->access_key_id, TEST_ACCESS_KEY_ID);
cos_str_set(&options->config->access_key_secret, TEST_ACCESS_KEY_SECRET);
cos_str_set(&options->config->appid, TEST_APPID);
options->config->is_cname = is_cname;
options->ctl = cos_http_controller_create(options->pool, 0);
cos_str_set(&bucket, TEST_BUCKET_NAME);

domain_result = cos_create_domain_params(options->pool);
status = cos_get_bucket_domain(options, &bucket, domain_result, &resp_headers);
log_status(status);
if (!cos_status_is_ok(status)) {
    cos_pool_destroy(pool);
    return;
}

char *line = NULL;
line = apr_psprintf(options->pool, "%.*s\n", domain_result->status.len, domain_result->status.data);
printf("status: %s", line);
line = apr_psprintf(options->pool, "%.*s\n", domain_result->name.len, domain_result->name.data);
printf("name: %s", line);
line = apr_psprintf(options->pool, "%.*s\n", domain_result->type.len, domain_result->type.data);
printf("type: %s", line);
line = apr_psprintf(options->pool, "%.*s\n", domain_result->forced_replacement.len, domain_result->forced_replacement.data);
printf("forced_replacement: %s", line);

cos_pool_destroy(pool);

Parameter description

Parameter name Description Type
OPTIONS COS request options Struct
Bucket Query the Bucket of the custom domain name in BucketName-APPID format. For more information, please see Naming convention String
Domain_params Bucket Custom Domain name configuration Information Struct
Status Domain name Activate / deactivate status, valid value ENABLED/DISABLED String
Name User's custom domain name. Valid values: letters, numbers, dots String
Type Bound real server type, valid value REST/WEBSITE String
Forced_replacement Replace the existing configuration with a valid value of CNAME/TXT. Enter forcefully verifies the ownership of the domain name, and then deliver configures it. String
Resp_headers Returns the header field of the HTTP response message Struct

Return result description

Returned Result Description Type
Code Error Codes Int
Error_code Error code content String
Error_msg Error code description String
Req_id Request message ID String