Object
# File lib/rack/cors.rb, line 19 def allow(&block) all_resources << (resources = Resources.new) if block.arity == 1 block.call(resources) else resources.instance_eval(&block) end end
# File lib/rack/cors.rb, line 29 def call(env) env['HTTP_ORIGIN'] = 'file://' if env['HTTP_ORIGIN'] == 'null' env['HTTP_ORIGIN'] ||= env['HTTP_X_ORIGIN'] cors_headers = nil if env['HTTP_ORIGIN'] debug(env) do [ 'Incoming Headers:', " Origin: #{env['HTTP_ORIGIN']}", " Access-Control-Request-Method: #{env['HTTP_ACCESS_CONTROL_REQUEST_METHOD']}", " Access-Control-Request-Headers: #{env['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}" ].join("\n") end if env['REQUEST_METHOD'] == 'OPTIONS' and env['HTTP_ACCESS_CONTROL_REQUEST_METHOD'] if headers = process_preflight(env) debug(env) do "Preflight Headers:\n" + headers.collect{|kv| " #{kv.join(': ')}"}.join("\n") end return [200, headers, []] end else cors_headers = process_cors(env) end end status, headers, body = @app.call env if cors_headers headers = headers.merge(cors_headers) # http://www.w3.org/TR/cors/#resource-implementation unless headers['Access-Control-Allow-Origin'] == '*' vary = headers['Vary'] headers['Vary'] = ((vary ? vary.split(/,\s*/) : []) + ['Origin']).uniq.join(', ') end end [status, headers, body] end
# File lib/rack/cors.rb, line 77 def all_resources @all_resources ||= [] end
# File lib/rack/cors.rb, line 68 def debug(env, message = nil, &block) if @debug_mode logger = @logger || env['rack.logger'] || begin @logger = ::Logger.new(STDOUT).tap {|logger| logger.level = ::Logger::Severity::INFO} end logger.debug(message, &block) end end
# File lib/rack/cors.rb, line 91 def find_resource(origin, path, env) all_resources.each do |r| if r.allow_origin?(origin, env) and found = r.find_resource(path) return found end end nil end
Generated with the Darkfish Rdoc Generator 2.