Class: Casper::Proxy

Inherits:
WEBrick::HTTPProxyServer
  • Object
show all
Defined in:
lib/casper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ Proxy

Returns a new instance of Proxy.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/casper.rb', line 10

def initialize(config={})
  @req_count = 0
  @hosts=[]
  @urls=[]
  @trace_domain = ""
  @trace_domain = config[:trace] if config[:trace] and ! config[:trace].empty?

  config[:Port] = 8080 if ! config[:Port]
  config[:AccessLog] = []
  config[:ProxyContentHandler] = Proc.new do |req, res| 
    log_requests(req, res) 
  end

  super(config)
end

Instance Attribute Details

#hostsObject (readonly)

Returns the value of attribute hosts.



8
9
10
# File 'lib/casper.rb', line 8

def hosts
  @hosts
end

#req_countObject (readonly)

Returns the value of attribute req_count.



7
8
9
# File 'lib/casper.rb', line 7

def req_count
  @req_count
end

Instance Method Details

#dumpObject



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/casper.rb', line 30

def dump
  $stdout.puts "Hosts we communicate with "
  if (@hosts.count == 0)
    $stdout.puts "None\n"

  else
    @hosts.each do |h|
      $stdout.puts " >>> #{h}\n"
    end
  end
end

#get_urlsObject



42
43
44
45
46
# File 'lib/casper.rb', line 42

def get_urls
  @urls.each do |u|
    $stdout.puts "#{u}\n"
  end
end

#infoObject



26
27
28
# File 'lib/casper.rb', line 26

def info
  $stdout.puts "[#{Time.now}] INFO #{@req_count} requests to #{@hosts.count} unique hosts"
end