Add rack middleware

master
Guillaume DOTT 2012-12-21 16:13:03 +01:00
parent d6820f3527
commit 5a4ca4d44a
2 changed files with 22 additions and 2 deletions

View File

@ -1,6 +1,7 @@
require 'net/dns' require 'net/dns'
require File.dirname(__FILE__) + "/project_honeypot/url.rb" require "project_honeypot/url"
require File.dirname(__FILE__) + "/project_honeypot/base.rb" require "project_honeypot/base"
require "project_honeypot/rack"
module ProjectHoneypot module ProjectHoneypot
class << self class << self

View File

@ -0,0 +1,19 @@
module ProjectHoneypot
class Rack
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)
env['PROJECT_HONEYPOT_SAFE'] = url.safe?
@app.call(request.env)
end
end
end