Permalink
Browse files

push header merge down to a private method so that live responses can…

… have their own header object
  • Loading branch information...
1 parent 8f0541b commit 38a3fed404e5e4f5c03be6f5288848d6d4f5d98c @tenderlove tenderlove committed Aug 13, 2012
View
9 actionpack/lib/action_controller/metal/live.rb
@@ -81,11 +81,6 @@ def to_hash
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 @@ def build_buffer(response, body)
body.each { |part| buf.write part }
buf
end
+
+ def merge_default_headers(original, default)
+ Header.new self, super
+ end
end
def process(name)
View
10 actionpack/lib/action_dispatch/http/response.rb
@@ -97,9 +97,7 @@ def closed?
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 @@ def cookies
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
View
11 actionpack/test/dispatch/live_response_test.rb
@@ -14,6 +14,17 @@ def test_header_merge
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

0 comments on commit 38a3fed

Please sign in to comment.