提交 4509494f 编写于 作者: A Aaron Patterson

header hash is duped before being sent up the rack stack

上级 b3d1f5b6
...@@ -71,6 +71,10 @@ def []=(k,v) ...@@ -71,6 +71,10 @@ def []=(k,v)
super super
end end
def to_hash
__getobj__.dup
end
end end
def initialize(status = 200, header = {}, body = []) def initialize(status = 200, header = {}, body = [])
......
...@@ -216,17 +216,7 @@ def close ...@@ -216,17 +216,7 @@ def close
end end
def to_a def to_a
assign_default_content_type_and_charset! rack_response @status, @header.to_hash
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
alias prepare! to_a alias prepare! to_a
alias to_ary to_a # For implicit splat on 1.9.2 alias to_ary to_a # For implicit splat on 1.9.2
...@@ -258,7 +248,7 @@ def munge_body_object(body) ...@@ -258,7 +248,7 @@ def munge_body_object(body)
body.respond_to?(:each) ? body : [body] body.respond_to?(:each) ? body : [body]
end end
def assign_default_content_type_and_charset! def assign_default_content_type_and_charset!(headers)
return if headers[CONTENT_TYPE].present? return if headers[CONTENT_TYPE].present?
@content_type ||= Mime::HTML @content_type ||= Mime::HTML
...@@ -269,5 +259,19 @@ def assign_default_content_type_and_charset! ...@@ -269,5 +259,19 @@ def assign_default_content_type_and_charset!
headers[CONTENT_TYPE] = type headers[CONTENT_TYPE] = type
end 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
end end
...@@ -12,6 +12,11 @@ def self.controller_path ...@@ -12,6 +12,11 @@ def self.controller_path
'test' 'test'
end end
def default_header
response.stream.write "<html><body>hi</body></html>"
response.stream.close
end
def basic_stream def basic_stream
response.headers['Content-Type'] = 'text/event-stream' response.headers['Content-Type'] = 'text/event-stream'
%w{ hello world }.each do |word| %w{ hello world }.each do |word|
...@@ -94,5 +99,13 @@ def test_thread_locals_get_copied ...@@ -94,5 +99,13 @@ def test_thread_locals_get_copied
get :thread_locals get :thread_locals
end 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
end end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册