aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2012-07-29 15:51:21 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2012-07-29 15:51:21 -0700
commit356787fce80ba545e288f464450483d52782871a (patch)
tree53736c756b5383806b78fadb834adb3a18892504 /actionpack/lib
parent76d75f42409a5711a772d78f67cb635b9b1e933a (diff)
downloadrails-356787fce80ba545e288f464450483d52782871a.tar.gz
rails-356787fce80ba545e288f464450483d52782871a.tar.bz2
rails-356787fce80ba545e288f464450483d52782871a.zip
adding a buffered stream to the response object
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_controller/metal.rb2
-rw-r--r--actionpack/lib/action_dispatch/http/response.rb44
2 files changed, 43 insertions, 3 deletions
diff --git a/actionpack/lib/action_controller/metal.rb b/actionpack/lib/action_controller/metal.rb
index 92433ab462..0a0f5393ce 100644
--- a/actionpack/lib/action_controller/metal.rb
+++ b/actionpack/lib/action_controller/metal.rb
@@ -187,7 +187,7 @@ module ActionController
end
def performed?
- !!response_body
+ response_body || (response && response.committed?)
end
def dispatch(name, request) #:nodoc:
diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb
index 5ef1c86967..912463bc0e 100644
--- a/actionpack/lib/action_dispatch/http/response.rb
+++ b/actionpack/lib/action_dispatch/http/response.rb
@@ -65,6 +65,36 @@ module ActionDispatch # :nodoc:
include ActionDispatch::Http::Cache::Response
include MonitorMixin
+ class Buffer # :nodoc:
+ def initialize(response, buf)
+ @response = response
+ @buf = buf
+ @closed = false
+ end
+
+ def write(string)
+ raise IOError, "closed stream" if closed?
+
+ @response.commit!
+ @buf.push string
+ end
+
+ def each(&block)
+ @buf.each(&block)
+ end
+
+ def close
+ @response.commit!
+ @closed = true
+ end
+
+ def closed?
+ @closed
+ end
+ end
+
+ attr_reader :stream
+
def initialize(status = 200, header = {}, body = [])
super()
@@ -76,6 +106,8 @@ module ActionDispatch # :nodoc:
@committed = false
@content_type = nil
@charset = nil
+ @stream = build_buffer self, @body
+
if content_type = self[CONTENT_TYPE]
type, charset = content_type.split(/;\s*charset=/)
@@ -102,7 +134,7 @@ module ActionDispatch # :nodoc:
end
def committed?
- synchronize { @committed }
+ @committed
end
def status=(status)
@@ -151,7 +183,7 @@ module ActionDispatch # :nodoc:
def body=(body)
@blank = true if body == EMPTY
- @body = body.respond_to?(:each) ? body : [body]
+ @body = munge_body_object(body)
end
def body_parts
@@ -214,6 +246,14 @@ module ActionDispatch # :nodoc:
private
+ def build_buffer(response, body)
+ Buffer.new response, body
+ end
+
+ def munge_body_object(body)
+ body.respond_to?(:each) ? body : [body]
+ end
+
def assign_default_content_type_and_charset!
return if headers[CONTENT_TYPE].present?