Class: Rack::Cors
- Inherits:
-
Object
show all
- Defined in:
- lib/rhoconnect/middleware/cors.rb
Defined Under Namespace
Classes: Resource, Resources
Instance Method Summary
collapse
Constructor Details
#initialize(app, opts = {}) {|_self| ... } ⇒ Cors
Returns a new instance of Cors.
6
7
8
9
10
|
# File 'lib/rhoconnect/middleware/cors.rb', line 6
def initialize(app, opts={})
@app = app
@logger = opts[:logger]
yield self if block_given?
end
|
Instance Method Details
#allow {|resources| ... } ⇒ Object
12
13
14
15
|
# File 'lib/rhoconnect/middleware/cors.rb', line 12
def allow
all_resources << (resources = Resources.new)
yield resources
end
|
#call(env) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/rhoconnect/middleware/cors.rb', line 17
def call(env)
if env['HTTP_ORIGIN'] == 'null'
env['HTTP_ORIGIN'] = 'file://'
end
if env['HTTP_X_ORIGIN'] and not env['HTTP_ORIGIN']
log 'ORIGIN header is empty, X-ORIGIN workaround header applied.'
env['HTTP_ORIGIN'] = env['HTTP_X_ORIGIN']
end
= nil
if env['HTTP_ORIGIN']
if env['REQUEST_METHOD'] == 'OPTIONS'
if = process_preflight(env)
return [200, , ['']]
end
else
= process_cors(env)
end
end
status, , body = @app.call env
= .merge() if
[status, , body]
end
|