Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
9f64f20b
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,发现更多精彩内容 >>
提交
9f64f20b
编写于
4月 30, 2012
作者:
S
Sergey Nartimov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
allow send_file/send_data to skip disposition header, closes #2973
上级
24f14378
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
22 addition
and
17 deletion
+22
-17
actionpack/lib/action_controller/metal/data_streaming.rb
actionpack/lib/action_controller/metal/data_streaming.rb
+11
-17
actionpack/test/controller/send_file_test.rb
actionpack/test/controller/send_file_test.rb
+11
-0
未找到文件。
actionpack/lib/action_controller/metal/data_streaming.rb
浏览文件 @
9f64f20b
...
...
@@ -8,10 +8,8 @@ module DataStreaming
include
ActionController
::
Rendering
DEFAULT_SEND_FILE_OPTIONS
=
{
:type
=>
'application/octet-stream'
.
freeze
,
:disposition
=>
'attachment'
.
freeze
,
}.
freeze
DEFAULT_SEND_FILE_TYPE
=
'application/octet-stream'
.
freeze
#:nodoc:
DEFAULT_SEND_FILE_DISPOSITION
=
'attachment'
.
freeze
#:nodoc:
protected
# Sends the file. This uses a server-appropriate method (such as X-Sendfile)
...
...
@@ -135,15 +133,8 @@ def send_data(data, options = {}) #:doc:
def
send_file_headers!
(
options
)
type_provided
=
options
.
has_key?
(
:type
)
options
.
update
(
DEFAULT_SEND_FILE_OPTIONS
.
merge
(
options
))
[
:type
,
:disposition
].
each
do
|
arg
|
raise
ArgumentError
,
":
#{
arg
}
option required"
if
options
[
arg
].
nil?
end
disposition
=
options
[
:disposition
]
disposition
+=
%(; filename="#{options[:filename]}")
if
options
[
:filename
]
content_type
=
options
[
:type
]
content_type
=
options
.
fetch
(
:type
,
DEFAULT_SEND_FILE_TYPE
)
raise
ArgumentError
,
":type option required"
if
content_type
.
nil?
if
content_type
.
is_a?
(
Symbol
)
extension
=
Mime
[
content_type
]
...
...
@@ -157,10 +148,13 @@ def send_file_headers!(options)
self
.
content_type
=
content_type
end
headers
.
merge!
(
'Content-Disposition'
=>
disposition
,
'Content-Transfer-Encoding'
=>
'binary'
)
disposition
=
options
.
fetch
(
:disposition
,
DEFAULT_SEND_FILE_DISPOSITION
)
unless
disposition
.
nil?
disposition
+=
%(; filename="#{options[:filename]}")
if
options
[
:filename
]
headers
[
'Content-Disposition'
]
=
disposition
end
headers
[
'Content-Transfer-Encoding'
]
=
'binary'
response
.
sending_file
=
true
...
...
actionpack/test/controller/send_file_test.rb
浏览文件 @
9f64f20b
...
...
@@ -154,6 +154,17 @@ def test_send_file_headers_guess_type_from_extension
end
end
def
test_send_file_with_default_content_disposition_header
process
(
'data'
)
assert_equal
'attachment'
,
@controller
.
headers
[
'Content-Disposition'
]
end
def
test_send_file_without_content_disposition_header
@controller
.
options
=
{
:disposition
=>
nil
}
process
(
'data'
)
assert_nil
@controller
.
headers
[
'Content-Disposition'
]
end
%w(file data)
.
each
do
|
method
|
define_method
"test_send_
#{
method
}
_status"
do
@controller
.
options
=
{
:stream
=>
false
,
:status
=>
500
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录