diff options
Diffstat (limited to 'lib/rainbows/reverse_proxy/synchronous.rb')
-rw-r--r-- | lib/rainbows/reverse_proxy/synchronous.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/rainbows/reverse_proxy/synchronous.rb b/lib/rainbows/reverse_proxy/synchronous.rb new file mode 100644 index 0000000..b5911a9 --- /dev/null +++ b/lib/rainbows/reverse_proxy/synchronous.rb @@ -0,0 +1,21 @@ +# -*- encoding: binary -*- +# :enddoc: +module Rainbows::ReverseProxy::Synchronous + UpstreamSocket = Rainbows::ReverseProxy::UpstreamSocket + + def each_block(input, &block) + buf = "" + while input.read(16384, buf) + yield buf + end + end + + def call(env) + input = prepare_input!(env) + req = build_headers(env, input) + sock = UpstreamSocket.new(pick_upstream(env)) + sock.write(req) + each_block(input) { |buf| sock.kgio_write(buf) } if input + Kcar::Response.new(sock).rack + end +end |