提交 38a3fed4 编写于 作者: A Aaron Patterson

push header merge down to a private method so that live responses can have their own header object

上级 8f0541b7
...@@ -81,11 +81,6 @@ def to_hash ...@@ -81,11 +81,6 @@ def to_hash
end end
end end
def initialize(status = 200, header = {}, body = [])
header = Header.new self, header
super(status, header, body)
end
def commit! def commit!
headers.freeze headers.freeze
super super
...@@ -98,6 +93,10 @@ def build_buffer(response, body) ...@@ -98,6 +93,10 @@ def build_buffer(response, body)
body.each { |part| buf.write part } body.each { |part| buf.write part }
buf buf
end end
def merge_default_headers(original, default)
Header.new self, super
end
end end
def process(name) def process(name)
......
...@@ -97,9 +97,7 @@ def closed? ...@@ -97,9 +97,7 @@ def closed?
def initialize(status = 200, header = {}, body = []) def initialize(status = 200, header = {}, body = [])
super() super()
if self.class.default_headers.respond_to?(:merge) header = merge_default_headers(header, self.class.default_headers)
header = self.class.default_headers.merge(header)
end
self.body, self.header, self.status = body, header, status self.body, self.header, self.status = body, header, status
...@@ -243,6 +241,12 @@ def cookies ...@@ -243,6 +241,12 @@ def cookies
private private
def merge_default_headers(original, default)
return original unless default.respond_to?(:merge)
default.merge(original)
end
def build_buffer(response, body) def build_buffer(response, body)
Buffer.new response, body Buffer.new response, body
end end
......
...@@ -14,6 +14,17 @@ def test_header_merge ...@@ -14,6 +14,17 @@ def test_header_merge
refute_equal header, @response.header refute_equal header, @response.header
end 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 def test_parallel
latch = ActiveSupport::Concurrency::Latch.new latch = ActiveSupport::Concurrency::Latch.new
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册