aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2012-07-29 17:26:07 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2012-07-29 21:43:05 -0700
commitaf0a9f9eefaee3a8120cfd8d05cbc431af376da3 (patch)
tree3eca858f42bf55c2e1d660434f3e782c524debab /actionpack/lib
parentd4433a35215c5e32d5cb91885c4084f849988887 (diff)
downloadrails-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')
-rw-r--r--actionpack/lib/action_controller.rb1
-rw-r--r--actionpack/lib/action_controller/metal/live.rb42
2 files changed, 43 insertions, 0 deletions
diff --git a/actionpack/lib/action_controller.rb b/actionpack/lib/action_controller.rb
index 7c10fcbb8a..1d06c83338 100644
--- a/actionpack/lib/action_controller.rb
+++ b/actionpack/lib/action_controller.rb
@@ -1,5 +1,6 @@
require 'abstract_controller'
require 'action_dispatch'
+require 'action_controller/metal/live'
module ActionController
extend ActiveSupport::Autoload
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