1 # -*- encoding: binary -*-
3 module Rainbows::ProcessClient
4 include Rainbows::Response
5 include Rainbows::Const
7 NULL_IO = Unicorn::HttpRequest::NULL_IO
8 RACK_INPUT = Unicorn::HttpRequest::RACK_INPUT
9 IC = Unicorn::HttpRequest.input_class
12 @hp = hp = Rainbows::HttpParser.new
13 kgio_read!(16384, buf = hp.buf) or return
17 timed_read(buf2 ||= "") or return
22 env[REMOTE_ADDR] = kgio_addr
23 status, headers, body = APP.call(env.merge!(RACK_DEFAULTS))
26 write(EXPECT_100_RESPONSE)
27 env.delete(HTTP_EXPECT)
28 status, headers, body = APP.call(env)
30 write_response(status, headers, body, alive = @hp.next?)
32 # if we get any error, try to write something back to the client
33 # assuming we haven't closed the socket, but don't get hung up
34 # if the socket is already closed or broken. We'll always ensure
35 # the socket is closed at the end of this function
43 Rainbows::Error.write(self, e)
46 def set_input(env, hp)
47 env[RACK_INPUT] = 0 == hp.content_length ? NULL_IO : IC.new(self, hp)