Class: Apia::CORS
- Inherits:
-
Object
- Object
- Apia::CORS
- Defined in:
- lib/apia/cors.rb
Instance Attribute Summary collapse
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#methods ⇒ Object
Returns the value of attribute methods.
-
#origin ⇒ Object
Returns the value of attribute origin.
Instance Method Summary collapse
-
#initialize ⇒ CORS
constructor
A new instance of CORS.
- #to_headers ⇒ Object
Constructor Details
#initialize ⇒ CORS
Returns a new instance of CORS.
10 11 12 13 14 |
# File 'lib/apia/cors.rb', line 10 def initialize @origin = '*' @methods = '*' @headers = [] end |
Instance Attribute Details
#headers ⇒ Object
Returns the value of attribute headers.
7 8 9 |
# File 'lib/apia/cors.rb', line 7 def headers @headers end |
#methods ⇒ Object
Returns the value of attribute methods.
6 7 8 |
# File 'lib/apia/cors.rb', line 6 def methods @methods end |
#origin ⇒ Object
Returns the value of attribute origin.
8 9 10 |
# File 'lib/apia/cors.rb', line 8 def origin @origin end |
Instance Method Details
#to_headers ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/apia/cors.rb', line 16 def to_headers return {} if @origin.nil? headers = {} headers['Access-Control-Allow-Origin'] = @origin if @methods.is_a?(String) headers['Access-Control-Allow-Methods'] = @methods elsif @methods.is_a?(Array) && @methods.any? headers['Access-Control-Allow-Methods'] = @methods.map(&:upcase).join(', ') end if @headers.is_a?(String) headers['Access-Control-Allow-Headers'] = @headers elsif @headers.is_a?(Array) && @headers.any? headers['Access-Control-Allow-Headers'] = @headers.join(', ') end headers end |