Help Center> Object Storage Service> API Reference> APIs> Advanced Bucket Settings> Configuring Mirroring Back-to-Source Rules
Updated on 2024-04-22 GMT+08:00

Configuring Mirroring Back-to-Source Rules

Functions

This operation configures mirroring back-to-source rules for a specified bucket. The API is idempotent. If there is already an identical rule for the bucket, a success message is returned with status code 200. Otherwise, status code 201 is returned.

Request Syntax

PUT /?mirrorBackToSource HTTP/1.1
Host: bucketname.obs.region.myhuaweicloud.com 
Authorization: authorization
Content-Type: application/json
Content-Length: length
Date: date

policy json body

Request Parameters

This request contains no message parameters.

Request Headers

This request uses common headers. For details, see Table 3.

Request Elements

Table 1 Request elements

Element

Description

Mandatory

rules

Number of rules.

Type: container

Value range: array size ranging from 1 to 10

NOTE:

For the same bucket, prefixes of different rules cannot contain each other or have duplicate beginning characters. The same agency is recommended.

Yes

Table 2 Rule parameters

Parameter

Description

Mandatory

id

Rule ID. Unique ID of a back-to-source rule configured for the current bucket.

Type: string

Value range: 1 to 256. The value must be within the range of ^[a-zA-Z0-9_-]{1, 256}$.

Yes

condition

Condition for triggering back-to-source.

Type: container

Yes

httpErrorCodeReturnedEquals

Error code that triggers the back-to-source function. When this error is returned for a download request, the back-to-source function is triggered.

Type: integer

Value range: 404

Yes

objectKeyPrefixEquals

Prefix of the object name that triggers the back-to-source function. Back-to-source is performed only when the specified object name prefix is contained in the request. If this parameter is left blank, all objects are matched by default. For the same bucket, prefixes of different rules cannot contain each other or have duplicate beginning characters.

Type: string

Valid value: a string of 0 to 1023 characters

No

redirect

Main parameters of back-to-source.

Type: container

Yes

agency

Agency name With an agency, the customer can grant OBS the permissions to query whether a specified object exists in the bucket and upload objects to the bucket.

Type: string

Yes

publicSource

Configuration of the source site that can be publicly accessed. This parameter is mandatory when the source site is a public accessible resource.

Type: container

No

sourceEndpoint

Source site address that can be publicly accessed.

Type: container

No

master

Primary source address. If the source is a bucket that can be accessed over HTTP network, the address is the bucket domain name. If the source is a private bucket provided by other cloud vendors, the address is a region domain name address.

Type: array

Valid value: A single source site address is in the format of https|http://xxx.yyy.zzz, containing 10 to 255 characters.

NOTE:

The primary source site address is preferentially used during the back-to-source process. If multiple primary addresses are configured, all primary addresses are accessed in polling mode. If two or more primary addresses are configured, when the first request to the primary address fails and the retry conditions are met, the request will retry another primary address.

At least one primary address must be configured.

A maximum of five primary addresses can be configured.

No

slave

Secondary source site address. If the source is a bucket that can be accessed over HTTP network, the address is the bucket domain name. If the source is a private bucket provided by other cloud vendors, the address is a region domain name address.

Type: array

Valid value: A single source site address is in the format of https|http://xxx.yyy.zzz, containing 10 to 255 characters.

NOTE:

A back-to-source request will retry the secondary source site address when primary source site address is not available.

A maximum of five secondary addresses can be configured.

No

retryConditions

Condition for switching the source site address.

Type: array

Value range: 4XX, 5XX, 400-499, and 500-599 error codes

NOTE:

Error codes starting with 4XX and 4 cannot be configured together. Error codes starting with 5XX and 5 cannot be configured together.

A maximum of 20 error codes can be configured.

No

passQueryString

Indicates whether to carry the request character string. If the value is true, the queryString value in the OBS request is passed to the source site. Otherwise, the queryString value will not be passed to the source site.

The default value is false. Value false indicates that the parameter is ignored.

Type: boolean

Value range: false or true

NOTE:

If the value is true but the query contains signature information, delete the signature information and pass the remaining parameters.

Yes

mirrorFollowRedirect

Indicates whether to obtain resources following the 3xx redirection request from the redirected source site. If the value is true, obtain resources following the 3xx redirection request from the redirected source site. Otherwise, OBS transparently passes the 3XX response and does not obtain resources. The default value is false. Value false indicates that the parameter is ignored.

Type: boolean

Value range: false or true

Yes

mirrorHttpHeader

HTTP header pass rule

Type: container

No

passAll

Indicates whether to pass all HTTP headers through the source site.

The following HTTP header types do not support passthrough:

1. Headers starting with the following prefixes:

x-obs-

x-amz-

2. All standard HTTP headers, for example:

Content-Length

Authorization

Date

passAll and pass are mutually exclusive.

Value type: BOOL

Value range: false or true

No

pass

Specifies the list of HTTP headers to be passed through.

Type: list

Value range: a maximum of 10 lists. The length of each list ranges from 1 to 63 characters. The key can contain only letters (both upper and lower cases), digits, hyphens (-), and underscores (_).

No

remove

List of HTTP headers that cannot be passed through.

The remove operation takes precedence over the pass and passAll operations.

Type: list

Value range: a maximum of 10 lists. The length of each list ranges from 1 to 63 characters. The key can contain only letters (both upper and lower cases), digits, hyphens (-), and underscores (_).

No

set

Configuration of list of HTTP headers to be passed through.

The set operation has a higher priority than the remove, pass, and passAll operations.

If the user-defined header contains Referer, redirectWithoutReferer must be set to true. Otherwise, Referer will be overwritten.

Type: list

Value range: a maximum of 10 lists

No

key

Keyword of the HTTP header that needs to be passed through.

Each key is unique.

Type: string

Value range: a string of 1 to 63 characters. Only letters (both upper and lower cases), digits, hyphens (-), and underscores (_) are allowed.

No

value

Value of the HTTP header that needs to be passed through.

Type: string

Value range: a string of 0 to 2048 characters

No

replaceKeyWith

Adds prefix or suffix. If you need to add a prefix or suffix when downloading objects from the source site, set this parameter to prefix${key}suffix. If no prefix or suffix needs to be added, set this parameter to ${key}.

Type: string

Value range: prefix${key}suffix

${key} is the keyword, prefix and suffix are the ones to be added. Total length of the prefix and suffix. The value ranges from 0 to 1023 characters.

No

replaceKeyPrefixWith

Character string used to replace the prefix objectKeyPrefixEquals. If you need to replace the current object name prefix when downloading objects from the source site, modify this configuration item.

If both replaceKeyWith and ReplaceKeyPrefixWith are empty, ReplaceKeyPrefixWith takes effect. The request is invalid if both the parameters are specified.

Type: string

Value range: a string of 0 to 1023 characters

No

vpcEndpointURN

URN of VPC Endpoint service.

Type: string

Value range: a string of 0 to 127 characters

No

redirectWithoutReferer

Indicates whether to carry the original host as the referer header to the destination address for redirection. Value false indicates that the original host will be carried, and true indicates that the original host will not be carried.

Type: boolean

Default value: false

No

mirrorAllowHttpMethod

If HEAD is added for a public bucket, you can use HEAD requests to retrieve objects' metadata, rather than objects, from the origin server.

Type: list

No

Response Syntax

HTTP/1.1 status
Server: OBS
Date: date
Content-Length: length

Response Headers

The response to the request uses common headers. For details, see Table 1.

Response Elements

This response contains no elements.

Error Responses

No special error responses are returned. For details about error responses, see Table 2 and Table 3.

Sample Request

PUT /?mirrorBackToSource HTTP/1.1
Host: bucketname.obs.region.myhuaweicloud.com 
Authorization: OBS H4IPJX0TQTHTHEBQQCEC:sc2PM13Wlfcoc/YZLK0MwsI2Zpo=
Content-Type: application/json
Content-Length: 1049
Date: Tue, 21 Jul 2020 15:38:30 GMT

{
    "rules": [{
        "id": "abc123",
        "condition": {
            "httpErrorCodeReturnedEquals": "404",
            "objectKeyPrefixEquals": "video/"
        },
        "redirect": {
            "agency": "agency",
            "publicSource": {
                "sourceEndpoint": {
                    "master":["http://bucket1.xxx.yyy.com", "https://bucket2.xxx.yyy.com"],
                    "slave": ["http://bucket3.xxx.yyy.com", "https://bucket4.xxx.yyy.com"]
                }
            },
            "retryConditions": ["4XX", "5XX"],
            "passQueryString": true,
            "mirrorFollowRedirect": true,
            "redirectWithoutReferer": true,
            "mirrorAllowHttpMethod":["HEAD"],
            "mirrorHttpHeader": {
                "passAll": false,
                "pass": ["content-encoding"],
                "remove": ["content-type"],
                "set": [{
                    "key": "helloworld",
                    "value": "2222"
                }]
            },
            "replaceKeyWith": "prefix${key}suffix",
            "replaceKeyPrefixWith": "picture/",
            "vpcEndpointURN": "001"
        }
    }]
}

Sample Response

HTTP/1.1 201 Created
Server: OBS
Date: Tue, 07 Jul 2020 07:29:13 GMT
Content-Length: 0