aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2012-07-29 20:26:40 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2012-07-29 21:43:07 -0700
commit4509494f702d58852ad47488ee1496dd34e31149 (patch)
treeec37229daf4c123764c2e9db9c63e49e714d7276 /actionpack
parentb3d1f5b630debcc2d0572a3e3af1855ef93300c2 (diff)
downloadrails-4509494f702d58852ad47488ee1496dd34e31149.tar.gz
rails-4509494f702d58852ad47488ee1496dd34e31149.tar.bz2
rails-4509494f702d58852ad47488ee1496dd34e31149.zip
header hash is duped before being sent up the rack stack
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_controller/metal/live.rb4
-rw-r--r--actionpack/lib/action_dispatch/http/response.rb28
-rw-r--r--actionpack/test/controller/live_stream_test.rb13
3 files changed, 33 insertions, 12 deletions
diff --git a/actionpack/lib/action_controller/metal/live.rb b/actionpack/lib/action_controller/metal/live.rb
index 3c1325cdb4..226943ff26 100644
--- a/actionpack/lib/action_controller/metal/live.rb
+++ b/actionpack/lib/action_controller/metal/live.rb
@@ -71,6 +71,10 @@ module ActionController # :nodoc:
super
end
+
+ def to_hash
+ __getobj__.dup
+ end
end
def initialize(status = 200, header = {}, body = [])
diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb
index fa48594c93..17e74656af 100644
--- a/actionpack/lib/action_dispatch/http/response.rb
+++ b/actionpack/lib/action_dispatch/http/response.rb
@@ -216,17 +216,7 @@ module ActionDispatch # :nodoc:
end
def to_a
- assign_default_content_type_and_charset!
- handle_conditional_get!
-
- @header[SET_COOKIE] = @header[SET_COOKIE].join("\n") if @header[SET_COOKIE].respond_to?(:join)
-
- if [204, 304].include?(@status)
- @header.delete CONTENT_TYPE
- [@status, @header, []]
- else
- [@status, @header, self]
- end
+ rack_response @status, @header.to_hash
end
alias prepare! to_a
alias to_ary to_a # For implicit splat on 1.9.2
@@ -258,7 +248,7 @@ module ActionDispatch # :nodoc:
body.respond_to?(:each) ? body : [body]
end
- def assign_default_content_type_and_charset!
+ def assign_default_content_type_and_charset!(headers)
return if headers[CONTENT_TYPE].present?
@content_type ||= Mime::HTML
@@ -269,5 +259,19 @@ module ActionDispatch # :nodoc:
headers[CONTENT_TYPE] = type
end
+
+ def rack_response(status, header)
+ assign_default_content_type_and_charset!(header)
+ handle_conditional_get!
+
+ header[SET_COOKIE] = header[SET_COOKIE].join("\n") if header[SET_COOKIE].respond_to?(:join)
+
+ if [204, 304].include?(@status)
+ header.delete CONTENT_TYPE
+ [status, header, []]
+ else
+ [status, header, self]
+ end
+ end
end
end
diff --git a/actionpack/test/controller/live_stream_test.rb b/actionpack/test/controller/live_stream_test.rb
index e5fb50fca4..74b223e4f5 100644
--- a/actionpack/test/controller/live_stream_test.rb
+++ b/actionpack/test/controller/live_stream_test.rb
@@ -12,6 +12,11 @@ module ActionController
'test'
end
+ def default_header
+ response.stream.write "<html><body>hi</body></html>"
+ response.stream.close
+ end
+
def basic_stream
response.headers['Content-Type'] = 'text/event-stream'
%w{ hello world }.each do |word|
@@ -94,5 +99,13 @@ module ActionController
get :thread_locals
end
+
+ def test_live_stream_default_header
+ @controller.request = @request
+ @controller.response = @response
+ @controller.process :default_header
+ _, headers, _ = @response.prepare!
+ assert headers['Content-Type']
+ end
end
end