Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
0eefa705
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 搜索 >>
提交
0eefa705
编写于
9月 30, 2008
作者:
M
Michael Koziarski
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix etag! and last_modified! to work as advertised.
Add tests too.
上级
0b465032
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
44 addition
and
3 deletion
+44
-3
actionpack/lib/action_controller/base.rb
actionpack/lib/action_controller/base.rb
+4
-2
actionpack/test/controller/render_test.rb
actionpack/test/controller/render_test.rb
+40
-1
未找到文件。
actionpack/lib/action_controller/base.rb
浏览文件 @
0eefa705
...
...
@@ -967,13 +967,15 @@ def head(*args)
# Sets the Last-Modified response header. Returns 304 Not Modified if the
# If-Modified-Since request header is <= last modified.
def
last_modified!
(
utc_time
)
head
(
:not_modified
)
if
response
.
last_modified!
(
utc_time
)
response
.
last_modified
=
utc_time
head
(
:not_modified
)
if
response
.
last_modified
==
request
.
if_modified_since
end
# Sets the ETag response header. Returns 304 Not Modified if the
# If-None-Match request header matches.
def
etag!
(
etag
)
head
(
:not_modified
)
if
response
.
etag!
(
etag
)
response
.
etag
=
etag
head
(
:not_modified
)
if
response
.
etag
==
request
.
if_none_match
end
# Clears the rendered results, allowing for another render to be performed.
...
...
actionpack/test/controller/render_test.rb
浏览文件 @
0eefa705
...
...
@@ -39,6 +39,16 @@ def conditional_hello
render
:action
=>
'hello_world'
end
end
def
conditional_hello_with_bangs
render
:action
=>
'hello_world'
end
before_filter
:handle_last_modified_and_etags
,
:only
=>
:conditional_hello_with_bangs
def
handle_last_modified_and_etags
last_modified!
Time
.
now
.
utc
.
beginning_of_day
etag!
[
:foo
,
123
]
end
def
render_hello_world
render
:template
=>
"test/hello_world"
...
...
@@ -1306,6 +1316,7 @@ def setup
@controller
=
TestController
.
new
@request
.
host
=
"www.nextangle.com"
@expected_bang_etag
=
etag_for
(
expand_key
([
:foo
,
123
]))
end
def
test_render_200_should_set_etag
...
...
@@ -1365,11 +1376,27 @@ def test_etag_should_govern_renders_with_layouts_too
assert_equal
"<wrapper>
\n
<html>
\n
<p>Hello </p>
\n
<p>This is grand!</p>
\n
</html>
\n
</wrapper>
\n
"
,
@response
.
body
assert_equal
etag_for
(
"<wrapper>
\n
<html>
\n
<p>Hello </p>
\n
<p>This is grand!</p>
\n
</html>
\n
</wrapper>
\n
"
),
@response
.
headers
[
'ETag'
]
end
def
test_etag_with_bang_should_set_etag
get
:conditional_hello_with_bangs
assert_equal
@expected_bang_etag
,
@response
.
headers
[
"ETag"
]
assert_response
:success
end
def
test_etag_with_bang_should_obey_if_none_match
@request
.
if_none_match
=
@expected_bang_etag
get
:conditional_hello_with_bangs
assert_response
:not_modified
end
protected
def
etag_for
(
text
)
%("#{Digest::MD5.hexdigest(text)}")
end
def
expand_key
(
args
)
ActiveSupport
::
Cache
.
expand_cache_key
(
args
)
end
end
class
LastModifiedRenderTest
<
Test
::
Unit
::
TestCase
...
...
@@ -1402,6 +1429,18 @@ def test_request_modified
assert
!
@response
.
body
.
blank?
assert_equal
@last_modified
,
@response
.
headers
[
'Last-Modified'
]
end
def
test_request_with_bang_gets_last_modified
get
:conditional_hello_with_bangs
assert_equal
@last_modified
,
@response
.
headers
[
'Last-Modified'
]
assert_response
:success
end
def
test_request_with_bang_obeys_last_modified
@request
.
if_modified_since
=
@last_modified
get
:conditional_hello_with_bangs
assert_response
:not_modified
end
end
class
RenderingLoggingTest
<
Test
::
Unit
::
TestCase
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录