diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-07-29 17:26:07 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-07-29 21:43:05 -0700 |
commit | af0a9f9eefaee3a8120cfd8d05cbc431af376da3 (patch) | |
tree | 3eca858f42bf55c2e1d660434f3e782c524debab /actionpack/lib/action_controller/metal | |
parent | d4433a35215c5e32d5cb91885c4084f849988887 (diff) | |
download | rails-af0a9f9eefaee3a8120cfd8d05cbc431af376da3.tar.gz rails-af0a9f9eefaee3a8120cfd8d05cbc431af376da3.tar.bz2 rails-af0a9f9eefaee3a8120cfd8d05cbc431af376da3.zip |
added live responses which can be written and read in separate threads
Diffstat (limited to 'actionpack/lib/action_controller/metal')
-rw-r--r-- | actionpack/lib/action_controller/metal/live.rb | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/actionpack/lib/action_controller/metal/live.rb b/actionpack/lib/action_controller/metal/live.rb new file mode 100644 index 0000000000..aea00849d3 --- /dev/null +++ b/actionpack/lib/action_controller/metal/live.rb @@ -0,0 +1,42 @@ +require 'action_dispatch/http/response' + +module ActionController + module Live + class Response < ActionDispatch::Response + class Buffer < ActionDispatch::Response::Buffer # :nodoc: + def initialize(response) + @response = response + @buf = Queue.new + end + + def write(string) + unless @response.committed? + @response.headers["Cache-Control"] = "no-cache" + @response.headers.delete("Content-Length") + end + + super + end + + def each + while str = @buf.pop + yield str + end + end + + def close + super + @buf.push nil + end + end + + private + + def build_buffer(response, body) + buf = Buffer.new response + body.each { |part| buf.write part } + buf + end + end + end +end |