Class: Rack::Cors::Resources
- Inherits:
-
Object
- Object
- Rack::Cors::Resources
- Defined in:
- lib/rhoconnect/middleware/cors.rb
Instance Method Summary collapse
- #allow_origin?(source) ⇒ Boolean
- #find_resource(path) ⇒ Object
-
#initialize ⇒ Resources
constructor
A new instance of Resources.
- #origins(*args) ⇒ Object
- #public_resources? ⇒ Boolean
- #resource(path, opts = {}) ⇒ Object
Constructor Details
#initialize ⇒ Resources
Returns a new instance of Resources.
62 63 64 65 66 |
# File 'lib/rhoconnect/middleware/cors.rb', line 62 def initialize @origins = [] @resources = [] @public_resources = false end |
Instance Method Details
#allow_origin?(source) ⇒ Boolean
93 94 95 96 97 98 |
# File 'lib/rhoconnect/middleware/cors.rb', line 93 def allow_origin?(source) result = public_resources? || @origins.include?(source) || (not (@origins.select {|n| n.class == Regexp && n.match(source)}).empty?) #TODO: to fix "n.match(source)". Unsure, but it may lead to security risks. result end |
#find_resource(path) ⇒ Object
100 101 102 |
# File 'lib/rhoconnect/middleware/cors.rb', line 100 def find_resource(path) @resources.detect{|r| r.match?(path)} end |
#origins(*args) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/rhoconnect/middleware/cors.rb', line 68 def origins(*args) @origins = args.flatten.collect do |n| if n.class == Regexp n else case n when /^[a-z]+:\/\// then n when '*' @public_resources = true n else "http://#{n}" end end end end |
#public_resources? ⇒ Boolean
89 90 91 |
# File 'lib/rhoconnect/middleware/cors.rb', line 89 def public_resources? @public_resources end |