Skip to content

Commit

Permalink
header hash is duped before being sent up the rack stack
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Jul 30, 2012
1 parent b3d1f5b commit 4509494
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
4 changes: 4 additions & 0 deletions actionpack/lib/action_controller/metal/live.rb
Expand Up @@ -71,6 +71,10 @@ def []=(k,v)

super
end

def to_hash
__getobj__.dup
end
end

def initialize(status = 200, header = {}, body = [])
Expand Down
28 changes: 16 additions & 12 deletions actionpack/lib/action_dispatch/http/response.rb
Expand Up @@ -216,17 +216,7 @@ def close
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
Expand Down Expand Up @@ -258,7 +248,7 @@ def munge_body_object(body)
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
Expand All @@ -269,5 +259,19 @@ def assign_default_content_type_and_charset!

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
13 changes: 13 additions & 0 deletions actionpack/test/controller/live_stream_test.rb
Expand Up @@ -12,6 +12,11 @@ def self.controller_path
'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|
Expand Down Expand Up @@ -94,5 +99,13 @@ def test_thread_locals_get_copied

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

0 comments on commit 4509494

Please sign in to comment.