Skip to content
igrigorik edited this page Aug 11, 2012 · 4 revisions

Connecting through an HTTP Proxy

You can route any em-http connection through an HTTP proxy (SSL tunneling is supported):

EventMachine.run do
  connection_opts = {
    :proxy => {
       :host => 'www.myproxy.com',
       :port => 8080,
       :authorization => ['username', 'password']
    }
  }

  http = EventMachine::HttpRequest.new('http://www.website.com/', connection_opts).get
  http.callback { }
end

Connecting through a SOCKS5 Proxy

Tunneling an em-http request connection through a SOCKS5 proxy is no more complicated than through a regular HTTP proxy:

EventMachine.run do
  connection_opts = {:proxy => {:host => 'www.myproxy.com', :port => 8080, :type => :socks5 }}

  http = EventMachine::HttpRequest.new('http://www.website.com/', connection_opts).get
  http.callback { }
end

In both cases (HTTP and SOCKS5), the authorization is optional based on whether your proxy requires it.