Skip to content

Commit

Permalink
push header merge down to a private method so that live responses can…
Browse files Browse the repository at this point in the history
… have their own header object
  • Loading branch information
tenderlove committed Aug 13, 2012
1 parent 8f0541b commit 38a3fed
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
9 changes: 4 additions & 5 deletions actionpack/lib/action_controller/metal/live.rb
Expand Up @@ -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
Expand All @@ -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)
Expand Down
10 changes: 7 additions & 3 deletions actionpack/lib/action_dispatch/http/response.rb
Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions actionpack/test/dispatch/live_response_test.rb
Expand Up @@ -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


Expand Down

0 comments on commit 38a3fed

Please sign in to comment.