1.62.2 (latest) 1.62.1 1.61.0 1.60.0 1.59.0 1.58.0 1.57.1 1.56.0 1.55.0 1.54.0 1.53.0 1.52.0 1.51.0 1.50.0 1.49.0 1.48.1 1.47.0 1.46.0 1.45.0 1.44.0 1.43.0 1.42.0 1.41.0 1.40.0 1.39.0 1.38.0 1.37.0 1.36.2 1.35.0 Reference documentation and code samples for the Cloud Storage API class Google::Cloud::Storage::Bucket::Cors.

## Bucket Cors

A special-case Array for managing the website CORS rules for a bucket.
Accessed via [#cors](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_cors_instance_ "Google::Cloud::Storage::Bucket#cors (method)").

## Inherits

- Array

## Examples

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

bucket.cors do |c|
  # Remove the last CORS rule from the array
  c.pop
  # Remove all existing rules with the https protocol
  c.delete_if { |r| r.origin.include? "http://example.com" }
  c.add_rule ["http://example.org", "https://example.org"],
             ["GET", "POST", "DELETE"],
             headers: ["X-My-Custom-Header"],
             max_age: 3600
end
```

Retrieving the bucket's CORS rules.

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"
bucket.cors.size #=> 2
rule = bucket.cors.first
rule.origin #=> ["http://example.org"]
rule.methods #=> ["GET","POST","DELETE"]
rule.headers #=> ["X-My-Custom-Header"]
rule.max_age #=> 3600
```

## Methods

### #add_rule

```ruby
def add_rule(origin, methods, headers: nil, max_age: nil)
```
Add a CORS rule to the CORS rules for a bucket. Accepts options for
setting preflight response headers. Preflight requests and responses
are required if the request method and headers are not both [simple
methods](http://www.w3.org/TR/cors/#simple-method) and [simple
headers](http://www.w3.org/TR/cors/#simple-header).
**Parameters**

- **origin** (String, Array\<String\>) --- The [origin](http://tools.ietf.org/html/rfc6454) or origins permitted for cross origin resource sharing with the bucket. Note: "\*" is permitted in the list of origins, and means "any Origin".
- **methods** (String, Array\<String\>) --- The list of HTTP methods permitted in cross origin resource sharing with the bucket. (GET, OPTIONS, POST, etc) Note: "\*" is permitted in the list of methods, and means "any method".
- **headers** (String, Array\<String\>) *(defaults to: nil)* --- The list of header field names to send in the Access-Control-Allow-Headers header in the preflight response. Indicates the custom request headers that may be used in the actual request.
- **max_age** (Integer) *(defaults to: nil)* --- The value to send in the Access-Control-Max-Age header in the preflight response. Indicates how many seconds the results of a preflight request can be cached in a preflight result cache. The default value is `1800` (30 minutes.)
**Example**

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.create_bucket "my-bucket" do |b|
  b.cors.add_rule ["http://example.org", "https://example.org"],
                  "*",
                  headers: ["X-My-Custom-Header"],
                  max_age: 300
end
```