Created
October 18, 2012 08:06
-
-
Save brainopia/3910381 to your computer and use it in GitHub Desktop.
Github mirror
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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