aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/metal/live.rb
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib/action_controller/metal/live.rb')
-rw-r--r--actionpack/lib/action_controller/metal/live.rb42
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