Class: ProxyTester::HttpProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/proxy_tester/http_proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection_string) ⇒ HttpProxy

Returns a new instance of HttpProxy.



13
14
15
16
17
18
19
20
21
# File 'lib/proxy_tester/http_proxy.rb', line 13

def initialize(connection_string)
  match = connection_string_pattern.match(connection_string) || {}

  raise Exceptions::ProxyConnectionStringInvalid, JSON.dump(connection_string: connection_string) if match[:host].blank?
  raise Exceptions::ProxyConnectionStringInvalid, JSON.dump(connection_string: connection_string) if match[:port].blank?

  @host = match[:host]
  @port = match[:port]
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



11
12
13
# File 'lib/proxy_tester/http_proxy.rb', line 11

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



11
12
13
# File 'lib/proxy_tester/http_proxy.rb', line 11

def port
  @port
end

Instance Method Details

#to_string(options = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/proxy_tester/http_proxy.rb', line 27

def to_string(options = {})
  result = []
  result << 'http://'

  if user and options[:cleartext] == true
    result << "#{user.name}:#{user.password}@" 
  elsif user
    result << "#{user.name}:#{'*' * 4}@" if user
  end

  result << "#{host}:#{port}"

  result.join
end

#use_user(user) ⇒ Object



23
24
25
# File 'lib/proxy_tester/http_proxy.rb', line 23

def use_user(user)
  @user = user
end