Sends a CORS (Cross-Origin Resource Sharing) preflight OPTIONS request to an object to verify whether the cross-origin request is permitted by OSS.
Usage notes
Before a cross-origin request is sent, the browser sends a preflight OPTIONS request to OSS. The request carries origin, HTTP method, and header information, which OSS evaluates against the bucket's CORS rules:
| Parameter | Matched against CORS rule field |
|---|---|
--origin | AllowedOrigins |
--access-control-request-method | AllowedMethods |
--access-control-request-headers | AllowedHeaders |
If any value does not match the CORS rules, none of the CORS response headers are returned.
The browser determines automatically whether a preflight request is needed. Use this command to test or debug CORS rules manually from the command line.
Command syntax
ossutil api option-object --bucket <value> --key <value> [flags]Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
--bucket | string | Yes | The name of the bucket. |
--key | string | Yes | The full path of the object. |
--origin | string | No | The origin of the cross-origin request. Matched against AllowedOrigins in the CORS configuration. |
--access-control-request-method | string | No | The HTTP method to be used in the actual cross-origin request. Matched against AllowedMethods in the CORS configuration. |
--access-control-request-headers | string | No | The custom request headers to be included in the actual cross-origin request. Matched against AllowedHeaders in the CORS configuration. |
For supported global flags, see Global command-line options.
Examples
Test a specific origin and HTTP method
The following command tests whether PUT requests from www.example.com are allowed on example.txt in examplebucket:
ossutil api option-object --bucket examplebucket --key example.txt \
--origin www.example.com \
--access-control-request-method PUTSend a basic OPTIONS request
ossutil api option-object --bucket examplebucket --key example.txtTest with a custom request header
ossutil api option-object --bucket examplebucket --key example.txt \
--access-control-request-headers x-oss-test1Test with an origin only
ossutil api option-object --bucket examplebucket --key example.txt \
--origin www.example.comWhat's next
To configure CORS rules on a bucket, see bucket-set-cors.
For the underlying API operation, see Options.