Skip to content

Instantly share code, notes, and snippets.

@almog
Forked from andrey-kazakov/socksify_faraday.rb
Last active May 20, 2017 11:56
Show Gist options
  • Select an option

  • Save almog/6528056 to your computer and use it in GitHub Desktop.

Select an option

Save almog/6528056 to your computer and use it in GitHub Desktop.

Revisions

  1. Almog Kurtser revised this gist Sep 11, 2013. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions socksify_mechanize.rb
    Original file line number Diff line number Diff line change
    @@ -2,9 +2,6 @@
    require "socksify"
    require 'socksify/http'

    # Mechanize: call @agent.set_socks(addr, port) before using
    # any of it's methods; it might be working in other cases,
    # but I just didn't tried :)
    class Mechanize::HTTP::Agent
    public
    def set_socks addr, port
    @@ -20,3 +17,6 @@ def http_class
    @http.socks_port = port
    end
    end

    agent = Mechanize.new
    agent.agent.set_socks('localhost', 9050) #Use Tor as proxy
  2. Lain Iwakura revised this gist Feb 17, 2012. 1 changed file with 22 additions and 0 deletions.
    22 changes: 22 additions & 0 deletions socksify_mechanize.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    # requires socksify gem
    require "socksify"
    require 'socksify/http'

    # Mechanize: call @agent.set_socks(addr, port) before using
    # any of it's methods; it might be working in other cases,
    # but I just didn't tried :)
    class Mechanize::HTTP::Agent
    public
    def set_socks addr, port
    set_http unless @http
    class << @http
    attr_accessor :socks_addr, :socks_port

    def http_class
    Net::HTTP.SOCKSProxy(socks_addr, socks_port)
    end
    end
    @http.socks_addr = addr
    @http.socks_port = port
    end
    end
  3. Lain Iwakura renamed this gist Feb 17, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. @andrey-kazakov andrey-kazakov created this gist Feb 17, 2012.
    18 changes: 18 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    # requires socksify gem
    require "socksify"
    require 'socksify/http'

    # use w/ OAuth2 like OAuth2::Client.new(id, secret, connection_opts: { proxy: 'socks://127.0.0.1:9050' })
    class Faraday::Adapter::NetHttp
    def net_http_class(env)
    if proxy = env[:request][:proxy]
    if proxy[:uri].scheme == 'socks'
    Net::HTTP::SOCKSProxy(proxy[:uri].host, proxy[:uri].port)
    else
    Net::HTTP::Proxy(proxy[:uri].host, proxy[:uri].port, proxy[:user], proxy[:password])
    end
    else
    Net::HTTP
    end
    end
    end