Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
0a958d84
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,发现更多精彩内容 >>
提交
0a958d84
编写于
12月 08, 2011
作者:
K
kennyj
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use freezed string constant. Some string literals is used repeatedly.
上级
0df2ef3e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
40 addition
and
24 deletion
+40
-24
actionpack/lib/action_dispatch/http/cache.rb
actionpack/lib/action_dispatch/http/cache.rb
+27
-15
actionpack/lib/action_dispatch/http/parameter_filter.rb
actionpack/lib/action_dispatch/http/parameter_filter.rb
+3
-1
actionpack/lib/action_dispatch/http/response.rb
actionpack/lib/action_dispatch/http/response.rb
+10
-8
未找到文件。
actionpack/lib/action_dispatch/http/cache.rb
浏览文件 @
0a958d84
...
...
@@ -4,14 +4,18 @@ module ActionDispatch
module
Http
module
Cache
module
Request
HTTP_IF_MODIFIED_SINCE
=
'HTTP_IF_MODIFIED_SINCE'
.
freeze
HTTP_IF_NONE_MATCH
=
'HTTP_IF_NONE_MATCH'
.
freeze
def
if_modified_since
if
since
=
env
[
'HTTP_IF_MODIFIED_SINCE'
]
if
since
=
env
[
HTTP_IF_MODIFIED_SINCE
]
Time
.
rfc2822
(
since
)
rescue
nil
end
end
def
if_none_match
env
[
'HTTP_IF_NONE_MATCH'
]
env
[
HTTP_IF_NONE_MATCH
]
end
def
not_modified?
(
modified_at
)
...
...
@@ -43,31 +47,35 @@ module Response
alias
:etag?
:etag
def
last_modified
if
last
=
headers
[
'Last-Modified'
]
if
last
=
headers
[
LAST_MODIFIED
]
Time
.
httpdate
(
last
)
end
end
def
last_modified?
headers
.
include?
(
'Last-Modified'
)
headers
.
include?
(
LAST_MODIFIED
)
end
def
last_modified
=
(
utc_time
)
headers
[
'Last-Modified'
]
=
utc_time
.
httpdate
headers
[
LAST_MODIFIED
]
=
utc_time
.
httpdate
end
def
etag
=
(
etag
)
key
=
ActiveSupport
::
Cache
.
expand_cache_key
(
etag
)
@etag
=
self
[
"ETag"
]
=
%("#{Digest::MD5.hexdigest(key)}")
@etag
=
self
[
ETAG
]
=
%("#{Digest::MD5.hexdigest(key)}")
end
private
LAST_MODIFIED
=
"Last-Modified"
.
freeze
ETAG
=
"ETag"
.
freeze
CACHE_CONTROL
=
"Cache-Control"
.
freeze
def
prepare_cache_control!
@cache_control
=
{}
@etag
=
self
[
"ETag"
]
@etag
=
self
[
ETAG
]
if
cache_control
=
self
[
"Cache-Control"
]
if
cache_control
=
self
[
CACHE_CONTROL
]
cache_control
.
split
(
/,\s*/
).
each
do
|
segment
|
first
,
last
=
segment
.
split
(
"="
)
@cache_control
[
first
.
to_sym
]
=
last
||
true
...
...
@@ -81,28 +89,32 @@ def handle_conditional_get!
end
end
DEFAULT_CACHE_CONTROL
=
"max-age=0, private, must-revalidate"
DEFAULT_CACHE_CONTROL
=
"max-age=0, private, must-revalidate"
.
freeze
NO_CACHE
=
"no-cache"
.
freeze
PUBLIC
=
"public"
.
freeze
PRIVATE
=
"private"
.
freeze
MUST_REVALIDATE
=
"must-revalidate"
.
freeze
def
set_conditional_cache_control!
return
if
self
[
"Cache-Control"
].
present?
return
if
self
[
CACHE_CONTROL
].
present?
control
=
@cache_control
if
control
.
empty?
headers
[
"Cache-Control"
]
=
DEFAULT_CACHE_CONTROL
headers
[
CACHE_CONTROL
]
=
DEFAULT_CACHE_CONTROL
elsif
control
[
:no_cache
]
headers
[
"Cache-Control"
]
=
"no-cache"
headers
[
CACHE_CONTROL
]
=
NO_CACHE
else
extras
=
control
[
:extras
]
max_age
=
control
[
:max_age
]
options
=
[]
options
<<
"max-age=
#{
max_age
.
to_i
}
"
if
max_age
options
<<
(
control
[
:public
]
?
"public"
:
"private"
)
options
<<
"must-revalidate"
if
control
[
:must_revalidate
]
options
<<
(
control
[
:public
]
?
PUBLIC
:
PRIVATE
)
options
<<
MUST_REVALIDATE
if
control
[
:must_revalidate
]
options
.
concat
(
extras
)
if
extras
headers
[
"Cache-Control"
]
=
options
.
join
(
", "
)
headers
[
CACHE_CONTROL
]
=
options
.
join
(
", "
)
end
end
end
...
...
actionpack/lib/action_dispatch/http/parameter_filter.rb
浏览文件 @
0a958d84
...
...
@@ -20,6 +20,8 @@ def enabled?
@filters
.
present?
end
FILTERED
=
'[FILTERED]'
.
freeze
def
compiled_filter
@compiled_filter
||=
begin
regexps
,
blocks
=
compile_filter
...
...
@@ -29,7 +31,7 @@ def compiled_filter
original_params
.
each
do
|
key
,
value
|
if
regexps
.
find
{
|
r
|
key
=~
r
}
value
=
'[FILTERED]'
value
=
FILTERED
elsif
value
.
is_a?
(
Hash
)
value
=
filter
(
value
)
elsif
value
.
is_a?
(
Array
)
...
...
actionpack/lib/action_dispatch/http/response.rb
浏览文件 @
0a958d84
...
...
@@ -53,8 +53,10 @@ class Response
# information.
attr_accessor
:charset
,
:content_type
CONTENT_TYPE
=
"Content-Type"
CONTENT_TYPE
=
"Content-Type"
.
freeze
SET_COOKIE
=
"Set-Cookie"
.
freeze
LOCATION
=
"Location"
.
freeze
cattr_accessor
(
:default_charset
)
{
"utf-8"
}
include
Rack
::
Response
::
Helpers
...
...
@@ -66,7 +68,7 @@ def initialize(status = 200, header = {}, body = [])
@sending_file
=
false
@blank
=
false
if
content_type
=
self
[
"Content-Type"
]
if
content_type
=
self
[
CONTENT_TYPE
]
type
,
charset
=
content_type
.
split
(
/;\s*charset=/
)
@content_type
=
Mime
::
Type
.
lookup
(
type
)
@charset
=
charset
||
self
.
class
.
default_charset
...
...
@@ -142,12 +144,12 @@ def delete_cookie(key, value={})
end
def
location
headers
[
'Location'
]
headers
[
LOCATION
]
end
alias_method
:redirect_url
,
:location
def
location
=
(
url
)
headers
[
'Location'
]
=
url
headers
[
LOCATION
]
=
url
end
def
close
...
...
@@ -158,10 +160,10 @@ def to_a
assign_default_content_type_and_charset!
handle_conditional_get!
@header
[
"Set-Cookie"
]
=
@header
[
"Set-Cookie"
].
join
(
"
\n
"
)
if
@header
[
"Set-Cookie"
].
respond_to?
(
:join
)
@header
[
SET_COOKIE
]
=
@header
[
SET_COOKIE
].
join
(
"
\n
"
)
if
@header
[
SET_COOKIE
].
respond_to?
(
:join
)
if
[
204
,
304
].
include?
(
@status
)
@header
.
delete
"Content-Type"
@header
.
delete
CONTENT_TYPE
[
@status
,
@header
,
[]]
else
[
@status
,
@header
,
self
]
...
...
@@ -175,7 +177,7 @@ def to_a
# assert_equal 'AuthorOfNewPage', r.cookies['author']
def
cookies
cookies
=
{}
if
header
=
self
[
"Set-Cookie"
]
if
header
=
self
[
SET_COOKIE
]
header
=
header
.
split
(
"
\n
"
)
if
header
.
respond_to?
(
:to_str
)
header
.
each
do
|
cookie
|
if
pair
=
cookie
.
split
(
';'
).
first
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录