Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
5a8a550a
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5a8a550a
编写于
6月 15, 2009
作者:
Y
Yehuda Katz + Carl Lerche
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Finish making things pass with updated internal content_type semantics
上级
c50b03b7
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
26 addition
and
59 deletion
+26
-59
actionpack/lib/action_controller/base/mime_responds.rb
actionpack/lib/action_controller/base/mime_responds.rb
+1
-1
actionpack/lib/action_controller/base/streaming.rb
actionpack/lib/action_controller/base/streaming.rb
+5
-4
actionpack/lib/action_controller/new_base/rack_convenience.rb
...onpack/lib/action_controller/new_base/rack_convenience.rb
+1
-1
actionpack/lib/action_controller/testing/process.rb
actionpack/lib/action_controller/testing/process.rb
+2
-0
actionpack/lib/action_dispatch/http/response.rb
actionpack/lib/action_dispatch/http/response.rb
+11
-45
actionpack/test/controller/content_type_test.rb
actionpack/test/controller/content_type_test.rb
+2
-2
actionpack/test/controller/send_file_test.rb
actionpack/test/controller/send_file_test.rb
+4
-6
未找到文件。
actionpack/lib/action_controller/base/mime_responds.rb
浏览文件 @
5a8a550a
...
...
@@ -125,7 +125,7 @@ def custom(mime_type, &block)
end
@controller
.
template
.
formats
=
[
mime_type
.
to_sym
]
@response
.
content_type
=
mime_type
.
to_s
@response
.
content_type
=
mime_type
block_given?
?
block
.
call
:
@controller
.
send
(
:render
,
:action
=>
@controller
.
action_name
)
end
...
...
actionpack/lib/action_controller/base/streaming.rb
浏览文件 @
5a8a550a
...
...
@@ -162,15 +162,16 @@ def send_file_headers!(options)
disposition
<<=
%(; filename="#{options[:filename]}")
if
options
[
:filename
]
content_type
=
options
[
:type
]
if
content_type
.
is_a?
(
Symbol
)
raise
ArgumentError
,
"Unknown MIME type
#{
options
[
:type
]
}
"
unless
Mime
::
EXTENSION_LOOKUP
.
has_key?
(
content_type
.
to_s
)
content_type
=
Mime
::
Type
.
lookup_by_extension
(
content_type
.
to_s
)
raise
ArgumentError
,
"Unknown MIME type
#{
options
[
:type
]
}
"
unless
Mime
::
EXTENSION_LOOKUP
.
key?
(
content_type
.
to_s
)
self
.
content_type
=
Mime
::
Type
.
lookup_by_extension
(
content_type
.
to_s
)
else
self
.
content_type
=
content_type
end
content_type
=
content_type
.
to_s
.
strip
# fixes a problem with extra '\r' with some browsers
headers
.
merge!
(
'Content-Length'
=>
options
[
:length
],
'Content-Type'
=>
content_type
,
'Content-Disposition'
=>
disposition
,
'Content-Transfer-Encoding'
=>
'binary'
)
...
...
actionpack/lib/action_controller/new_base/rack_convenience.rb
浏览文件 @
5a8a550a
...
...
@@ -3,7 +3,7 @@ module RackConvenience
extend
ActiveSupport
::
Concern
included
do
delegate
:headers
,
:status
=
,
:location
=
,
delegate
:headers
,
:status
=
,
:location
=
,
:content_type
=
,
:status
,
:location
,
:content_type
,
:to
=>
"@_response"
attr_internal
:request
,
:response
end
...
...
actionpack/lib/action_controller/testing/process.rb
浏览文件 @
5a8a550a
...
...
@@ -56,6 +56,8 @@ def recycle!
@block
=
nil
@length
=
0
@body
=
[]
@charset
=
nil
@content_type
=
nil
@request
=
@template
=
nil
end
...
...
actionpack/lib/action_dispatch/http/response.rb
浏览文件 @
5a8a550a
...
...
@@ -67,12 +67,7 @@ def body
end
def
body
=
(
body
)
@body
=
if
body
.
respond_to?
(
:to_str
)
[
body
]
else
body
end
@body
=
body
.
respond_to?
(
:to_str
)
?
[
body
]
:
body
end
def
body_parts
...
...
@@ -96,36 +91,7 @@ def location=(url)
# If a character set has been defined for this response (see charset=) then
# the character set information will also be included in the content type
# information.
def
content_type
=
(
mime_type
)
self
.
headers
[
"Content-Type"
]
=
if
mime_type
=~
/charset/
||
(
c
=
charset
).
nil?
mime_type
.
to_s
else
"
#{
mime_type
}
; charset=
#{
c
}
"
end
end
# Returns the response's content MIME type, or nil if content type has been set.
def
content_type
content_type
=
String
(
headers
[
"Content-Type"
]
||
headers
[
"type"
]).
split
(
";"
)[
0
]
content_type
.
blank?
?
nil
:
content_type
end
# Set the charset of the Content-Type header. Set to nil to remove it.
# If no content type is set, it defaults to HTML.
def
charset
=
(
charset
)
headers
[
"Content-Type"
]
=
if
charset
"
#{
content_type
||
Mime
::
HTML
}
; charset=
#{
charset
}
"
else
content_type
||
Mime
::
HTML
.
to_s
end
end
def
charset
charset
=
String
(
headers
[
"Content-Type"
]
||
headers
[
"type"
]).
split
(
";"
)[
1
]
charset
.
blank?
?
nil
:
charset
.
strip
.
split
(
"="
)[
1
]
end
attr_accessor
:charset
,
:content_type
def
last_modified
if
last
=
headers
[
'Last-Modified'
]
...
...
@@ -162,15 +128,15 @@ def sending_file?
end
def
assign_default_content_type_and_charset!
if
type
=
headers
[
'Content-Type'
]
||
headers
[
'type'
]
unless
type
=~
/charset=/
||
sending_file?
headers
[
'Content-Type'
]
=
"
#{
type
}
; charset=
#{
default_charset
}
"
end
else
type
=
Mime
::
HTML
.
to_s
type
+=
"; charset=
#{
default_
charset
}
"
unless
sending_file?
headers
[
'Content-Type'
]
=
type
end
return
if
!
headers
[
"Content-Type"
].
blank?
@content_type
||=
Mime
::
HTML
@charset
||=
default_charset
type
=
@content_type
.
to_s
.
dup
type
<<
"; charset=
#{
@
charset
}
"
unless
sending_file?
headers
[
"Content-Type"
]
=
type
end
def
prepare!
...
...
actionpack/test/controller/content_type_test.rb
浏览文件 @
5a8a550a
...
...
@@ -83,14 +83,14 @@ def test_render_changed_charset_default
# :ported:
def
test_content_type_from_body
get
:render_content_type_from_body
assert_equal
"application/rss+xml"
,
@response
.
content_type
assert_equal
Mime
::
RSS
,
@response
.
content_type
assert_equal
"utf-8"
,
@response
.
charset
end
# :ported:
def
test_content_type_from_render
get
:render_content_type_from_render
assert_equal
"application/rss+xml"
,
@response
.
content_type
assert_equal
Mime
::
RSS
,
@response
.
content_type
assert_equal
"utf-8"
,
@response
.
charset
end
...
...
actionpack/test/controller/send_file_test.rb
浏览文件 @
5a8a550a
...
...
@@ -91,10 +91,10 @@ def test_data
def
test_headers_after_send_shouldnt_include_charset
response
=
process
(
'data'
)
assert_equal
"application/octet-stream"
,
response
.
content_type
assert_equal
"application/octet-stream"
,
response
.
headers
[
"Content-Type"
]
response
=
process
(
'file'
)
assert_equal
"application/octet-stream"
,
response
.
content_type
assert_equal
"application/octet-stream"
,
response
.
headers
[
"Content-Type"
]
end
# Test that send_file_headers! is setting the correct HTTP headers.
...
...
@@ -116,7 +116,7 @@ def test_send_file_headers!
h
=
@controller
.
headers
assert_equal
1
,
h
[
'Content-Length'
]
assert_equal
'image/png'
,
h
[
'Content-Type'
]
assert_equal
'image/png'
,
@controller
.
content_type
assert_equal
'disposition; filename="filename"'
,
h
[
'Content-Disposition'
]
assert_equal
'binary'
,
h
[
'Content-Transfer-Encoding'
]
...
...
@@ -136,9 +136,7 @@ def test_send_file_headers_with_mime_lookup_with_symbol
@controller
.
headers
=
{}
@controller
.
send
(
:send_file_headers!
,
options
)
headers
=
@controller
.
headers
assert_equal
'image/png'
,
headers
[
'Content-Type'
]
assert_equal
'image/png'
,
@controller
.
content_type
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录