Skip to content
igrigorik edited this page Apr 17, 2011 · 4 revisions

Connecting through an HTTP Proxy

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

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

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

Connecting through a SOCKS5 Proxy

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

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

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

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