Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
28a1a399
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,体验更适合开发者的 AI 搜索 >>
提交
28a1a399
编写于
10月 01, 2015
作者:
J
Jeremy Daer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Response#add_header for adding to multi-valued headers like Vary
上级
dd57f60d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
79 addition
and
0 deletion
+79
-0
actionpack/lib/action_dispatch/http/response.rb
actionpack/lib/action_dispatch/http/response.rb
+20
-0
actionpack/test/dispatch/response_test.rb
actionpack/test/dispatch/response_test.rb
+59
-0
未找到文件。
actionpack/lib/action_dispatch/http/response.rb
浏览文件 @
28a1a399
...
...
@@ -161,6 +161,26 @@ def get_header(key); headers[key]; end
def
set_header
(
key
,
v
);
headers
[
key
]
=
v
;
end
def
delete_header
(
key
);
headers
.
delete
key
;
end
# Add a header that may have multiple values.
#
# Example:
# response.add_header 'Vary', 'Accept'
# response.add_header 'Vary', 'Accept-Encoding'
# response.add_header 'Vary', 'Cookie'
#
# assert_equal 'Accept,Accept-Encoding,Cookie', response.get_header 'Vary'
#
# http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2
def
add_header
(
key
,
v
)
if
v
.
nil?
get_header
key
elsif
have_header?
key
set_header
key
,
"
#{
get_header
key
}
,
#{
v
}
"
else
set_header
key
,
v
end
end
def
await_commit
synchronize
do
@cv
.
wait_until
{
@committed
}
...
...
actionpack/test/dispatch/response_test.rb
浏览文件 @
28a1a399
...
...
@@ -293,6 +293,65 @@ def test_only_set_charset_still_defaults_to_text_html
end
end
class
ResponseHeadersTest
<
ActiveSupport
::
TestCase
def
setup
@response
=
ActionDispatch
::
Response
.
create
@response
.
set_header
'Foo'
,
'1'
end
test
'have_header?'
do
assert
@response
.
have_header?
'Foo'
assert_not
@response
.
have_header?
'foo'
assert_not
@response
.
have_header?
nil
end
test
'get_header'
do
assert_equal
'1'
,
@response
.
get_header
(
'Foo'
)
assert_nil
@response
.
get_header
(
'foo'
)
assert_nil
@response
.
get_header
(
nil
)
end
test
'set_header'
do
assert_equal
'2'
,
@response
.
set_header
(
'Foo'
,
'2'
)
assert
@response
.
have_header?
(
'Foo'
)
assert_equal
'2'
,
@response
.
get_header
(
'Foo'
)
assert_nil
@response
.
set_header
(
'Foo'
,
nil
)
assert
@response
.
have_header?
(
'Foo'
)
assert_nil
@response
.
get_header
(
'Foo'
)
end
test
'delete_header'
do
assert_nil
@response
.
delete_header
(
nil
)
assert_nil
@response
.
delete_header
(
'foo'
)
assert
@response
.
have_header?
(
'Foo'
)
assert_equal
'1'
,
@response
.
delete_header
(
'Foo'
)
assert_not
@response
.
have_header?
(
'Foo'
)
end
test
'add_header'
do
# Add a value to an existing header
assert_equal
'1,2'
,
@response
.
add_header
(
'Foo'
,
'2'
)
assert_equal
'1,2'
,
@response
.
get_header
(
'Foo'
)
# Add nil to an existing header
assert_equal
'1,2'
,
@response
.
add_header
(
'Foo'
,
nil
)
assert_equal
'1,2'
,
@response
.
get_header
(
'Foo'
)
# Add nil to a nonexistent header
assert_nil
@response
.
add_header
(
'Bar'
,
nil
)
assert_not
@response
.
have_header?
(
'Bar'
)
assert_nil
@response
.
get_header
(
'Bar'
)
# Add a value to a nonexistent header
assert_equal
'1'
,
@response
.
add_header
(
'Bar'
,
'1'
)
assert
@response
.
have_header?
(
'Bar'
)
assert_equal
'1'
,
@response
.
get_header
(
'Bar'
)
end
end
class
ResponseIntegrationTest
<
ActionDispatch
::
IntegrationTest
test
"response cache control from railsish app"
do
@app
=
lambda
{
|
env
|
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录