diff options
author | Eric Wong <normalperson@yhbt.net> | 2011-03-17 02:33:25 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2011-03-17 02:33:48 +0000 |
commit | 1f29269eabd806f1e0cb9ca7fd4231d8588d7669 (patch) | |
tree | 6def9afa046c2164183b6b2f34f6e9af95008a7b | |
parent | 57c9f70fb3c14ed94f4fb2445a8a4168f8c5253b (diff) | |
download | raindrops-1f29269eabd806f1e0cb9ca7fd4231d8588d7669.tar.gz |
watcher: properly stream responses for <= HTTP/1.0
nginx makes HTTP/1.0 requests and expects HTTP/1.1 responses
-rw-r--r-- | lib/raindrops/watcher.rb | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/lib/raindrops/watcher.rb b/lib/raindrops/watcher.rb index 51e1b19..877f80a 100644 --- a/lib/raindrops/watcher.rb +++ b/lib/raindrops/watcher.rb @@ -294,9 +294,7 @@ class Raindrops::Watcher end def tail(addr, env) - [ 200, - { "Transfer-Encoding" => "chunked", "Content-Type" => "text/plain" }, - Tailer.new(self, addr, env) ] + Tailer.new(self, addr, env).finish end # :startdoc: @@ -313,6 +311,18 @@ class Raindrops::Watcher len = Rack::Utils.bytesize(addr) len = 35 if len > 35 @fmt = "%20s % #{len}s % 10u % 10u\n" + case env["HTTP_VERSION"] + when "HTTP/1.0", nil + @chunk = false + else + @chunk = true + end + end + + def finish + headers = { "Content-Type" => "text/plain" } + headers["Transfer-Encoding"] = "chunked" if @chunk + [ 200, headers, self ] end # called by the Rack server @@ -323,9 +333,10 @@ class Raindrops::Watcher stats.queued >= @queued_min or next stats.active >= @active_min or next body = sprintf(@fmt, time.iso8601, @addr, stats.active, stats.queued) - yield "#{body.size.to_s(16)}\r\n#{body}\r\n" + body = "#{body.size.to_s(16)}\r\n#{body}\r\n" if @chunk + yield body end while true - yield "0\r\n\r\n" + yield "0\r\n\r\n" if @chunk end end |