diff options
Diffstat (limited to 'lib/rainbows/reverse_proxy/ev_client.rb')
-rw-r--r-- | lib/rainbows/reverse_proxy/ev_client.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/rainbows/reverse_proxy/ev_client.rb b/lib/rainbows/reverse_proxy/ev_client.rb new file mode 100644 index 0000000..94e7f82 --- /dev/null +++ b/lib/rainbows/reverse_proxy/ev_client.rb @@ -0,0 +1,39 @@ +# -*- encoding: binary -*- +# :enddoc: +require 'tempfile' +module Rainbows::ReverseProxy::EvClient + include Rainbows::ReverseProxy::Synchronous + AsyncCallback = "async.callback" + CBB = Unicorn::TeeInput.client_body_buffer_size + Content_Length = "Content-Length" + Transfer_Encoding = "Transfer-Encoding" + + def receive_data(buf) + if @body + @body << buf + else + response = @parser.headers(@headers, @rbuf << buf) or return + if (cl = @headers[Content_Length] && cl.to_i > CBB) || + (%r{\bchunked\b} =~ @headers[Transfer_Encoding]) + @body = LargeBody.new("") + @body << @rbuf + @response = response << @body + else + @body = @rbuf.dup + @response = response << [ @body ] + end + end + end + + class LargeBody < Tempfile + def each(&block) + buf = "" + rewind + while read(16384, buf) + yield buf + end + end + + alias close close! + end +end |