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.
16 17 18 |
# File 'lib/proxifier/proxy.rb', line 16 def @options end |
#url ⇒ Object (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
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
38 39 40 |
# File 'lib/proxifier/proxy.rb', line 38 def proxify?(host) self.class.proxify?(host, [:no_proxy]) end |
#query_options ⇒ Object
50 51 52 |
# File 'lib/proxifier/proxy.rb', line 50 def @query_options ||= query ? Hash[query.split("&").map { |q| q.split("=") }] : {} end |