class Proxifier::Proxy

Attributes

options[R]
url[R]

Public Class Methods

new(url, options = {}) click to toggle source
# 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
proxify?(host, no_proxy = nil) click to toggle source
# 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

Public Instance Methods

open(host, port, local_host = nil, local_port = nil) click to toggle source
# 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) click to toggle source
# File lib/proxifier/proxy.rb, line 42
def proxify(socket, host, port)
  do_proxify(socket, host, port)
end
proxify?(host) click to toggle source
# File lib/proxifier/proxy.rb, line 38
def proxify?(host)
  self.class.proxify?(host, options[:no_proxy])
end
query_options() click to toggle source
# File lib/proxifier/proxy.rb, line 50
def query_options
  @query_options ||= query ? Hash[query.split("&").map { |q| q.split("=") }] : {}
end

Protected Instance Methods

do_proxify(socket, host, port) click to toggle source
# File lib/proxifier/proxy.rb, line 59
def do_proxify(socket, host, port)
  raise NotImplementedError, "#{self} must implement do_proxify"
end