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
24
25
26
# 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 || {}

  unless @options['update_frequency'].to_i == 0
    log_message "Starting update timer... (updating every #{@options['update_frequency']} seconds)"
    run_update_timer
  end
end

Instance Method Details

#call(env) ⇒ Object



28
29
30
31
# File 'lib/rack-detect-tor.rb', line 28

def call(env)
  env['tor_exit_user'] = @tor_exits.include? request_ip(env)
  @app.call(env)
end