1 # -*- encoding: binary -*-
5 # base module for evented models like Rev and EventMachine
8 include Rainbows::Const
12 klass.const_set(:APP, G.server.app)
16 @remote_addr = ::TCPSocket === @_io ? @_io.peeraddr.last : LOCALHOST
19 @state = :headers # [ :body [ :trailers ] ] :app_call :close
23 # graceful exit, like SIGQUIT
29 msg = Error.response(e) and write(msg)
34 # TeeInput doesn't map too well to this right now...
38 @hp.headers(@env, @buf << data) or return
40 len = @hp.content_length
42 @input = HttpRequest::NULL_IO
43 app_call # common case
45 # since we don't do streaming input, we have no choice but
46 # to take over 100-continue handling from the Rack application
47 if @env[HTTP_EXPECT] =~ /\A100-continue\z/i
48 write(EXPECT_100_RESPONSE)
49 @env.delete(HTTP_EXPECT)
51 @input = len && len <= MAX_BODY ? StringIO.new("") : Util.tmpio
52 @hp.filter_body(@buf2 = @buf.dup, @buf)
61 @hp.filter_body(@buf2, @buf << data)
66 if @hp.trailers(@env, @buf << data)
69 @input.close if File === @input