Class: Beats::Rack::Cors

Inherits:
Object
  • Object
show all
Includes:
Goliath::Rack::AsyncMiddleware
Defined in:
lib/beats/rack/cors.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{
  :origin => '*',
  :methods => 'GET',
  :headers => 'Accept, Authorization, Content-Type, Origin',
  :expose_headers => 'Cache-Control, Content-Language, Content-Type, Expires, Last-Modified, Location, Pragma'
}

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Cors

Returns a new instance of Cors.



15
16
17
18
# File 'lib/beats/rack/cors.rb', line 15

def initialize(app, options = {})
  super(app)
  @options = DEFAULT_OPTIONS.merge(options)
end

Instance Method Details

#call(env) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/beats/rack/cors.rb', line 20

def call(env)
  if env['REQUEST_METHOD'] == 'OPTIONS'
    [200, cors_headers, []]
  else
    super(env)
  end
end

#post_process(env, status, headers, body) ⇒ Object



28
29
30
# File 'lib/beats/rack/cors.rb', line 28

def post_process(env, status, headers, body)
  [status, cors_headers.merge(headers), body]
end