Class: Hula::HttpProxyUpstreamSocks

Inherits:
Object
  • Object
show all
Includes:
Hula::Helpers::SocketTools
Defined in:
lib/hula/http_proxy_upstream_socks.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Hula::Helpers::SocketTools

free_port, port_open?, wait_for_port

Constructor Details

#initialize(polipo_bin: 'polipo', socks_proxy:, http_host: 'localhost', http_port: free_port) ⇒ HttpProxyUpstreamSocks

Returns a new instance of HttpProxyUpstreamSocks.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/hula/http_proxy_upstream_socks.rb', line 17

def initialize(
  polipo_bin: 'polipo',
  socks_proxy:,
  http_host: 'localhost',
  http_port: free_port
)
  @socks_proxy_host = socks_proxy.socks_host
  @socks_proxy_port = socks_proxy.socks_port
  @http_host = http_host
  @http_port = http_port
  @polipo_bin = polipo_bin

  check_polipo_bin!
end

Instance Attribute Details

#http_hostObject (readonly)

Returns the value of attribute http_host.



32
33
34
# File 'lib/hula/http_proxy_upstream_socks.rb', line 32

def http_host
  @http_host
end

#http_portObject (readonly)

Returns the value of attribute http_port.



32
33
34
# File 'lib/hula/http_proxy_upstream_socks.rb', line 32

def http_port
  @http_port
end

Instance Method Details

#startObject



34
35
36
# File 'lib/hula/http_proxy_upstream_socks.rb', line 34

def start
  @process ||= start_polipo_process
end

#stopObject



38
39
40
41
42
43
44
# File 'lib/hula/http_proxy_upstream_socks.rb', line 38

def stop
  return unless @process

  Process.kill('TERM', @process) rescue Errno::ESRCH
  Process.wait(@process)         rescue Errno::ECHILD
  @process = nil
end