0.0
No commit activity in last 3 years
No release in over 3 years
EventMachine CONNECTify shim: adds CONNECT support to any protocol.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0

Runtime

>= 1.0.0.beta.4
 Project Readme

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')