diff options
author | Eric Wong <normalperson@yhbt.net> | 2010-07-19 10:09:57 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2010-07-19 17:04:27 -0700 |
commit | 53b04c96d38bc6bb5fb3b4874fbf59aae81eb6f0 (patch) | |
tree | bf28e1cdefd32bcbe00fb892cade452e278f8f17 /lib/rainbows/rev/client.rb | |
parent | 1e6d3d19da2b62bfe7f8fd7827dcad3ee3fe9923 (diff) | |
download | rainbows-53b04c96d38bc6bb5fb3b4874fbf59aae81eb6f0.tar.gz |
This makes it easier to write proxies for slow clients that benefit from keep-alive. We also need to be careful about non-HTTP/1.1 connections that can't do keepalive, now.
Diffstat (limited to 'lib/rainbows/rev/client.rb')
-rw-r--r-- | lib/rainbows/rev/client.rb | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/lib/rainbows/rev/client.rb b/lib/rainbows/rev/client.rb index f067d1b..5c61109 100644 --- a/lib/rainbows/rev/client.rb +++ b/lib/rainbows/rev/client.rb @@ -52,6 +52,10 @@ module Rainbows schedule_write end + def next + @deferred_bodies.shift + end + def timeout? @_write_buffer.empty? && @deferred_bodies.empty? and close.nil? end @@ -69,25 +73,20 @@ module Rainbows status, headers, body = response headers = @hp.headers? ? HH.new(headers) : nil + headers[CONNECTION] = alive ? KEEP_ALIVE : CLOSE if headers if body.respond_to?(:to_path) io = body_to_io(body) st = io.stat if st.file? - if headers - headers[CONNECTION] = alive ? KEEP_ALIVE : CLOSE - write(response_header(status, headers)) - end + write(response_header(status, headers)) if headers return defer_body(to_sendfile(io)) elsif st.socket? || st.pipe? return stream_response(status, headers, io, body) end # char or block device... WTF? fall through to body.each end - if headers - headers[CONNECTION] = alive ? KEEP_ALIVE : CLOSE - write(response_header(status, headers)) - end + write(response_header(status, headers)) if headers write_body_each(self, body) end |