Created
February 20, 2019 01:00
-
-
Save bryanp/c6c688a7274c4b0f23c6598ca33dd415 to your computer and use it in GitHub Desktop.
Ruby Async Proxy
This file contains hidden or 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
class Proxy | |
def initialize(port:, host:) | |
@port, @host = port, host | |
@destination = "#{@host}:#{@port}" | |
@client = Async::HTTP::Client.new( | |
Async::HTTP::URLEndpoint.parse( | |
"http://#{@destination}" | |
) | |
) | |
end | |
def call(request) | |
# Do something with the request. | |
@client.call(request) | |
end | |
end | |
endpoint = Async::HTTP::URLEndpoint.parse( | |
"http://localhost:3000" | |
) | |
proxy = Proxy.new( | |
host: "localhost", port: 4242 | |
) | |
Async::Reactor.run do | |
Async::HTTP::Server.new(proxy, endpoint).run | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment