Class: Rack::DetectTor

Inherits:
Object
  • Object
show all
Defined in:
lib/rack-detect-tor.rb

Instance Method Summary collapse

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, options={})
  @app = app

  @options = {
    'external_ip'      => nil, 
    'external_port'    => nil,
    'update_frequency' => 60*60
  }.merge(options)

  @identifier = Hash[@options.select{|k,v| k =~ /^external_/}.
                     sort_by{|k,v| k}].values.map{|v| v.to_s == '' ? '*' : v}.join('/')

  log_message '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