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.



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

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.



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

def options
  @options
end

#urlObject (readonly)

Returns the value of attribute url.



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

def url
  @url
end

Class Method Details

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

Returns:

  • (Boolean)


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

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



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

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

#proxify?(host) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#query_optionsObject



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

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