diff options
author | Eric Wong <normalperson@yhbt.net> | 2010-10-20 17:48:58 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2010-10-21 00:49:36 +0000 |
commit | d4a2b5dd2b85f4b2d3bb120ee1e1b0dde31bc25c (patch) | |
tree | 85866cc775a213216701ccaedf16061f15d13975 /lib/rainbows/fiber/rev.rb | |
parent | a085ba3586756ac1f778d2862f75889de2449b0e (diff) | |
download | rainbows-d4a2b5dd2b85f4b2d3bb120ee1e1b0dde31bc25c.tar.gz |
We get basic internal API changes from Unicorn, code simplifications coming next.
Diffstat (limited to 'lib/rainbows/fiber/rev.rb')
-rw-r--r-- | lib/rainbows/fiber/rev.rb | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/lib/rainbows/fiber/rev.rb b/lib/rainbows/fiber/rev.rb index 2c1abb7..6969f5b 100644 --- a/lib/rainbows/fiber/rev.rb +++ b/lib/rainbows/fiber/rev.rb @@ -78,16 +78,17 @@ module Rainbows::Fiber def process(io) G.cur += 1 client = FIO.new(io, ::Fiber.current) - buf = client.read_timeout or return hp = HttpParser.new - env = {} + client.readpartial(16384, buf = hp.buf) begin # loop - buf << (client.read_timeout or return) until hp.headers(env, buf) + until env = hp.parse + buf << (client.read_timeout or return) + end env[CLIENT_IO] = client env[RACK_INPUT] = 0 == hp.content_length ? - HttpRequest::NULL_IO : TeeInput.new(client, env, hp, buf) + HttpRequest::NULL_IO : TeeInput.new(client, hp) env[REMOTE_ADDR] = io.kgio_addr status, headers, body = APP.call(env.update(RACK_DEFAULTS)) @@ -100,16 +101,12 @@ module Rainbows::Fiber if hp.headers? headers = HH.new(headers) range = make_range!(env, status, headers) and status = range.shift - headers[CONNECTION] = if hp.keepalive? && G.alive - KEEP_ALIVE - else - env = false - CLOSE - end + env = hp.keepalive? && G.alive + headers[CONNECTION] = env ? KEEP_ALIVE : CLOSE client.write(response_header(status, headers)) end write_body(client, body, range) - end while env && env.clear && hp.reset.nil? + end while env && hp.reset.nil? rescue => e Error.write(io, e) ensure |