1 # -*- encoding: binary -*-
5 # base module for evented models like Rev and EventMachine
8 include Rainbows::Const
11 # Apps may return this Rack response: AsyncResponse = [ -1, {}, [] ]
12 ASYNC_CALLBACK = "async.callback".freeze
14 ASYNC_CLOSE = "async.close".freeze
17 @remote_addr = ::TCPSocket === @_io ? @_io.peeraddr.last : LOCALHOST
20 @state = :headers # [ :body [ :trailers ] ] :app_call :close
24 # graceful exit, like SIGQUIT
30 msg = Error.response(e) and write(msg)
35 # TeeInput doesn't map too well to this right now...
39 @hp.headers(@env, @buf << data) or return
41 len = @hp.content_length
43 @input = HttpRequest::NULL_IO
44 app_call # common case
46 # since we don't do streaming input, we have no choice but
47 # to take over 100-continue handling from the Rack application
48 if @env[HTTP_EXPECT] =~ /\A100-continue\z/i
49 write(EXPECT_100_RESPONSE)
50 @env.delete(HTTP_EXPECT)
52 @input = len && len <= MAX_BODY ? StringIO.new("") : Util.tmpio
53 @hp.filter_body(@buf2 = "", @buf)
62 @hp.filter_body(@buf2, @buf << data)
67 if @hp.trailers(@env, @buf << data)