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
30 when EOFError,Errno::ECONNRESET,Errno::EPIPE,Errno::EINVAL,Errno::EBADF
32 when HttpParserError # try to tell the client they're bad
35 G.server.logger.error "Read error: #{e.inspect}"
36 G.server.logger.error e.backtrace.join("\n")
44 # TeeInput doesn't map too well to this right now...
48 @hp.headers(@env, @buf << data) or return
50 len = @hp.content_length
52 @input = HttpRequest::NULL_IO
53 app_call # common case
55 # since we don't do streaming input, we have no choice but
56 # to take over 100-continue handling from the Rack application
57 if @env[HTTP_EXPECT] =~ /\A100-continue\z/i
58 write(EXPECT_100_RESPONSE)
59 @env.delete(HTTP_EXPECT)
61 @input = len && len <= MAX_BODY ? StringIO.new("") : Util.tmpio
62 @hp.filter_body(@buf2 = @buf.dup, @buf)
71 @hp.filter_body(@buf2, @buf << data)
76 if @hp.trailers(@env, @buf << data)
78 @input.close if File === @input