class Rack::Cors::Halt

Constants

VERSION

Public Class Methods

new(app) click to toggle source
# File lib/rack/cors/halt.rb, line 7
def initialize(app)
  @app = app
end

Public Instance Methods

call(env) click to toggle source
# File lib/rack/cors/halt.rb, line 11
def call(env)
  if(env['X_RACK_CORS'].hit || !http_origin_header_present?(env))
    @app.call(env)
  else
    not_valid_reason = {
      hit: env['X_RACK_CORS'].hit,
      miss_reason: env['X_RACK_CORS'].miss_reason,
      preflight: env['X_RACK_CORS'].preflight
    }
    [200, {"Content-Type" => "application/json"}, [not_valid_reason.to_json]]
  end
end

Private Instance Methods

http_origin_header_present?(env) click to toggle source
# File lib/rack/cors/halt.rb, line 26
def http_origin_header_present?(env)
  env['HTTP_ORIGIN'].to_s != ''
end