Class: Rack::DetectTor
- Inherits:
-
Object
- Object
- Rack::DetectTor
- Defined in:
- lib/rack-detect-tor.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ DetectTor
constructor
A new instance of DetectTor.
Constructor Details
#initialize(app, options = {}) ⇒ DetectTor
Returns a new instance of DetectTor.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/rack-detect-tor.rb', line 7 def initialize(app, ={}) @app = app @options = { 'external_ip' => nil, 'external_port' => nil, 'update_frequency' => 60*60 }.merge() @identifier = Hash[@options.select{|k,v| k =~ /^external_/}. sort_by{|k,v| k}].values.map{|v| v.to_s == '' ? '*' : v}.join('/') 'Fetching initial list of tor exits...' @tor_exits = fetch_tor_exits || {} start_update_timer unless @options['update_frequency'].to_i == 0 end |
Instance Method Details
#call(env) ⇒ Object
25 26 27 28 |
# File 'lib/rack-detect-tor.rb', line 25 def call(env) env['tor_exit_user'] = @tor_exits.include? Rack::Request.new(env).ip unless env['tor_exit_user'] == true @app.call(env) end |