aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/lib/action_controller/metal/live.rb9
-rw-r--r--actionpack/lib/action_dispatch/http/response.rb10
-rw-r--r--actionpack/test/dispatch/live_response_test.rb11
3 files changed, 22 insertions, 8 deletions
diff --git a/actionpack/lib/action_controller/metal/live.rb b/actionpack/lib/action_controller/metal/live.rb
index bba75b22fd..32e5afa335 100644
--- a/actionpack/lib/action_controller/metal/live.rb
+++ b/actionpack/lib/action_controller/metal/live.rb
@@ -81,11 +81,6 @@ module ActionController
end
end
- def initialize(status = 200, header = {}, body = [])
- header = Header.new self, header
- super(status, header, body)
- end
-
def commit!
headers.freeze
super
@@ -98,6 +93,10 @@ module ActionController
body.each { |part| buf.write part }
buf
end
+
+ def merge_default_headers(original, default)
+ Header.new self, super
+ end
end
def process(name)
diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb
index 5014ad80aa..11b7534ea4 100644
--- a/actionpack/lib/action_dispatch/http/response.rb
+++ b/actionpack/lib/action_dispatch/http/response.rb
@@ -97,9 +97,7 @@ module ActionDispatch # :nodoc:
def initialize(status = 200, header = {}, body = [])
super()
- if self.class.default_headers.respond_to?(:merge)
- header = self.class.default_headers.merge(header)
- end
+ header = merge_default_headers(header, self.class.default_headers)
self.body, self.header, self.status = body, header, status
@@ -243,6 +241,12 @@ module ActionDispatch # :nodoc:
private
+ def merge_default_headers(original, default)
+ return original unless default.respond_to?(:merge)
+
+ default.merge(original)
+ end
+
def build_buffer(response, body)
Buffer.new response, body
end
diff --git a/actionpack/test/dispatch/live_response_test.rb b/actionpack/test/dispatch/live_response_test.rb
index 153f58c42c..e16f23914b 100644
--- a/actionpack/test/dispatch/live_response_test.rb
+++ b/actionpack/test/dispatch/live_response_test.rb
@@ -14,6 +14,17 @@ module ActionController
refute_equal header, @response.header
end
+ def test_initialize_with_default_headers
+ r = Class.new(Live::Response) do
+ def self.default_headers
+ { 'omg' => 'g' }
+ end
+ end
+
+ header = r.new.header
+ assert_kind_of(ActionController::Live::Response::Header, header)
+ end
+
def test_parallel
latch = ActiveSupport::Concurrency::Latch.new