Skip to content

Instantly share code, notes, and snippets.

@brainopia
Created October 18, 2012 08:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brainopia/3910381 to your computer and use it in GitHub Desktop.
Save brainopia/3910381 to your computer and use it in GitHub Desktop.
Github mirror
require 'eventmachine'
class Request < EM::P::HeaderAndContentProtocol
CRLF = "\r\n"
def receive_request(headers, body)
receive_full_request headers.join(CRLF) << CRLF*2 << body
end
end
class Client < Request
def receive_full_request(api_request)
api_request.sub! /Host:.*/i, 'Host: api.github.com'
EM.connect 'github.com', 443, Github, self, api_request
end
end
class Github < Request
def initialize(client, api_request)
super()
@client = client
@api_request = api_request
end
def post_init
start_tls
end
def ssl_handshake_completed
send_data @api_request
end
def receive_full_request(github_response)
@client.send_data github_response
close_connection_after_writing
@client.close_connection_after_writing
end
end
EM.run do
EM.start_server '0.0.0.0', ENV['PORT'], Client
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment