Class: Proxifier::Proxy
- Inherits:
-
Object
- Object
- Proxifier::Proxy
- Defined in:
- lib/proxifier/env.rb,
lib/proxifier/proxy.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(url, options = {}) ⇒ Proxy
constructor
A new instance of Proxy.
- #open(host, port, local_host = nil, local_port = nil) ⇒ Object
- #proxify(socket, host, port) ⇒ Object
- #proxify?(host) ⇒ Boolean
- #query_options ⇒ Object
Constructor Details
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
17 18 19 |
# File 'lib/proxifier/proxy.rb', line 17 def @options end |
#url ⇒ Object (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
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
39 40 41 |
# File 'lib/proxifier/proxy.rb', line 39 def proxify?(host) self.class.proxify?(host, [:no_proxy]) end |
#query_options ⇒ Object
51 52 53 |
# File 'lib/proxifier/proxy.rb', line 51 def @query_options ||= query ? Hash[query.split("&").map { |q| q.split("=") }] : {} end |