Class: Proxifier::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/proxifier/env.rb,
lib/proxifier/proxy.rb

Direct Known Subclasses

HTTPProxy, SOCKSProxy

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, options = {}) ⇒ Proxy

Returns a new instance of Proxy.



18
19
20
21
# File 'lib/proxifier/proxy.rb', line 18

def initialize(url, options = {})
  url = URI.parse(uri) unless url.is_a?(URI::Generic)
  @url, @options = url, options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



16
17
18
# File 'lib/proxifier/proxy.rb', line 16

def options
  @options
end

#urlObject (readonly)

Returns the value of attribute url.



16
17
18
# File 'lib/proxifier/proxy.rb', line 16

def url
  @url
end

Class Method Details

.proxify?(host, no_proxy = nil) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
11
12
13
# File 'lib/proxifier/proxy.rb', line 8

def proxify?(host, no_proxy = nil)
  return true unless no_proxy

  dont_proxy = no_proxy.split(",")
  dont_proxy.none? { |h| host =~ /#{h}\Z/ }
end

Instance Method Details

#open(host, port, local_host = nil, local_port = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/proxifier/env.rb', line 6

def open(host, port, local_host = nil, local_port = nil)
  return TCPSocket.new(host, port, local_host, local_port, :proxy => nil) unless proxify?(host)

  socket = TCPSocket.new(self.host, self.port, local_host, local_port, :proxy => nil)

  begin
    proxify(socket, host, port)
  rescue
    socket.close
    raise
  end

  socket
end

#proxify(socket, host, port) ⇒ Object



42
43
44
# File 'lib/proxifier/proxy.rb', line 42

def proxify(socket, host, port)
  do_proxify(socket, host, port)
end

#proxify?(host) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/proxifier/proxy.rb', line 38

def proxify?(host)
  self.class.proxify?(host, options[:no_proxy])
end

#query_optionsObject



50
51
52
# File 'lib/proxifier/proxy.rb', line 50

def query_options
  @query_options ||= query ? Hash[query.split("&").map { |q| q.split("=") }] : {}
end