xepoll_thread_*/client: EPOLLONESHOT implies EPOLLET
[rainbows.git] / lib / rainbows / reverse_proxy / ev_client.rb
blobcf97c4dba2f38a06ad907327c1819ae9df7135da
1 # -*- encoding: binary -*-
2 # :enddoc:
3 require 'tempfile'
4 module Rainbows::ReverseProxy::EvClient
5   include Rainbows::ReverseProxy::Synchronous
6   AsyncCallback = "async.callback"
7   CBB = Unicorn::TeeInput.client_body_buffer_size
8   Content_Length = "Content-Length"
9   Transfer_Encoding = "Transfer-Encoding"
11   def receive_data(buf)
12     if @body
13       @body << buf
14     else
15       response = @parser.headers(@headers, @rbuf << buf) or return
16       if (cl = @headers[Content_Length] && cl.to_i > CBB) ||
17          (%r{\bchunked\b} =~ @headers[Transfer_Encoding])
18         @body = LargeBody.new("")
19         @body << @rbuf
20         @response = response << @body
21       else
22         @body = @rbuf.dup
23         @response = response << [ @body ]
24       end
25     end
26   end
28   class LargeBody < Tempfile
29     def each
30       buf = ""
31       rewind
32       while read(16384, buf)
33         yield buf
34       end
35     end
37     alias close close!
38   end
39 end