a transparent CONNECT proxy wrapper for eventmachine
Ruby
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib ruby1.8 support for Base64.strict_encode64 Jun 11, 2013
spec
LICENSE.MIT
README.md
em-connectify.gemspec

README.md

EM-Connectify: Transparent CONNECT support for any EventMachine protocol

Heavily based on igrigorik's em-socksify, em-connectify provides a simple shim to send an eventmachine connection via an HTTP CONNECT proxy.

Example

class Handler < EM::Connection
  include EM::Connectify

  def connection_completed
    connectify('google.ca', 80) do
      send_data "GET / HTTP/1.1\r\nConnection:close\r\nHost: google.ca\r\n\r\n"
    end
  end

  def receive_data
    p data
  end
end

EM.run do
  EventMachine.connect PROXY_HOST, PROXY_PORT, Handler
end

What's happening here? First, we open a raw TCP connection to the CONNECT proxy (after all, all data will flow through it). Then, we provide a Handler connection class, which includes "EM::Connectify". Once the TCP connection is established, EventMachine calls the connection_completed method in our handler. Here, we call connectify with the actual destination host & port (address that we actually want to get to), and the module does the rest.

After you call connectify, the module temporarily intercepts your receive_data callbacks, negotiates the connection, and then once all is done, returns the control back to your code. Simple as that.

Authorization

If you need to log into your proxy server, pass the username and password to connectify and em-connectify will send a Proxy-Authorization: Basic header.

connectify('google.ca', 80, 'username', 'password')