Module: Sinatra::CrossOrigin::Helpers
- Defined in:
- lib/sinatra/cross_origin.rb
Instance Method Summary collapse
-
#cross_origin(hash = nil) ⇒ Object
Apply cross origin headers either from global config or custom config passed as a hash.
Instance Method Details
#cross_origin(hash = nil) ⇒ Object
Apply cross origin headers either from global config or custom config passed as a hash
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/sinatra/cross_origin.rb', line 28 def cross_origin(hash=nil) return unless request.env['HTTP_ORIGIN'] settings.set hash if hash origin = settings.allow_origin == :any ? request.env['HTTP_ORIGIN'] : settings.allow_origin methods = settings.allow_methods.map{ |m| m.to_s.upcase! }.join(', ') headers_list = { 'Access-Control-Allow-Origin' => origin, 'Access-Control-Allow-Methods' => methods, 'Access-Control-Allow-Headers' => settings.allow_headers.map(&:to_s).join(', '), 'Access-Control-Allow-Credentials' => settings.allow_credentials.to_s, 'Access-Control-Max-Age' => settings.max_age.to_s, 'Access-Control-Expose-Headers' => settings.expose_headers.join(', ') } headers headers_list end |