22 lines
496 B
Ruby
Raw Normal View History

module ProjectHoneypot::Rack
class Forbidden
2012-12-21 16:13:03 +01:00
def initialize(app, options={})
@app = app
raise ArgumentError, 'Must specify an API key' unless options[:api_key]
ProjectHoneypot.api_key = options[:api_key]
end
def call(env)
request = ::Rack::Request.new(env)
url = ProjectHoneypot.lookup(request.ip)
if url.safe?
@app.call(request.env)
else
[403, {"Content-Type" => "text/html"}, ["Forbidden"]]
end
2012-12-21 16:13:03 +01:00
end
end
end