Skip to content

Instantly share code, notes, and snippets.

@bryanp
Created February 20, 2019 01:00
Show Gist options
  • Save bryanp/c6c688a7274c4b0f23c6598ca33dd415 to your computer and use it in GitHub Desktop.
Save bryanp/c6c688a7274c4b0f23c6598ca33dd415 to your computer and use it in GitHub Desktop.
Ruby Async Proxy
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