Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
2e22c7fd
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,发现更多精彩内容 >>
提交
2e22c7fd
编写于
12月 18, 2008
作者:
J
Joshua Peek
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Conditionally inject session middleware instead of using session management
上级
2eb2ec9e
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
55 addition
and
41 deletion
+55
-41
actionpack/lib/action_controller/dispatcher.rb
actionpack/lib/action_controller/dispatcher.rb
+15
-2
actionpack/lib/action_controller/middleware_stack.rb
actionpack/lib/action_controller/middleware_stack.rb
+10
-6
actionpack/lib/action_controller/session/abstract_store.rb
actionpack/lib/action_controller/session/abstract_store.rb
+13
-1
actionpack/lib/action_controller/session/cookie_store.rb
actionpack/lib/action_controller/session/cookie_store.rb
+17
-3
actionpack/lib/action_controller/session_management.rb
actionpack/lib/action_controller/session_management.rb
+0
-29
未找到文件。
actionpack/lib/action_controller/dispatcher.rb
浏览文件 @
2e22c7fd
...
...
@@ -44,9 +44,22 @@ def to_prepare(identifier = nil, &block)
cattr_accessor
:middleware
self
.
middleware
=
MiddlewareStack
.
new
do
|
middleware
|
middleware
.
use
"ActionController::Lock"
,
:if
=>
lambda
{
!
ActionController
::
Base
.
allow_concurrency
}
middleware
.
use
"ActionController::Lock"
,
:if
=>
lambda
{
!
ActionController
::
Base
.
allow_concurrency
}
middleware
.
use
"ActionController::Failsafe"
middleware
.
use
"ActionController::SessionManagement::Middleware"
[
"ActionController::Session::CookieStore"
,
"ActionController::Session::MemCacheStore"
,
"ActiveRecord::SessionStore"
].
each
do
|
store
|
middleware
.
use
(
store
,
ActionController
::
Base
.
session_options
,
:if
=>
lambda
{
if
session_store
=
ActionController
::
Base
.
session_store
session_store
.
name
==
store
end
}
)
end
end
include
ActiveSupport
::
Callbacks
...
...
actionpack/lib/action_controller/middleware_stack.rb
浏览文件 @
2e22c7fd
module
ActionController
class
MiddlewareStack
<
Array
class
Middleware
attr_reader
:
klass
,
:
args
,
:block
attr_reader
:args
,
:block
def
initialize
(
klass
,
*
args
,
&
block
)
if
klass
.
is_a?
(
Class
)
@klass
=
klass
else
@klass
=
klass
.
to_s
.
constantize
end
@klass
=
klass
options
=
args
.
extract_options!
if
options
.
has_key?
(
:if
)
...
...
@@ -22,6 +18,14 @@ def initialize(klass, *args, &block)
@block
=
block
end
def
klass
if
@klass
.
is_a?
(
Class
)
@klass
else
@klass
.
to_s
.
constantize
end
end
def
active?
if
@conditional
.
respond_to?
(
:call
)
@conditional
.
call
...
...
actionpack/lib/action_controller/session/abstract_store.rb
浏览文件 @
2e22c7fd
...
...
@@ -60,7 +60,7 @@ def load!
end
DEFAULT_OPTIONS
=
{
:key
=>
'
rack.session
'
,
:key
=>
'
_session_id
'
,
:path
=>
'/'
,
:domain
=>
nil
,
:expire_after
=>
nil
,
...
...
@@ -70,6 +70,18 @@ def load!
}
def
initialize
(
app
,
options
=
{})
# Process legacy CGI options
options
=
options
.
symbolize_keys
if
options
.
has_key?
(
:session_path
)
options
[
:path
]
=
options
.
delete
(
:session_path
)
end
if
options
.
has_key?
(
:session_key
)
options
[
:key
]
=
options
.
delete
(
:session_key
)
end
if
options
.
has_key?
(
:session_http_only
)
options
[
:httponly
]
=
options
.
delete
(
:session_http_only
)
end
@app
=
app
@default_options
=
DEFAULT_OPTIONS
.
merge
(
options
)
@key
=
@default_options
[
:key
]
...
...
actionpack/lib/action_controller/session/cookie_store.rb
浏览文件 @
2e22c7fd
...
...
@@ -41,9 +41,11 @@ class CookieStore
SECRET_MIN_LENGTH
=
30
# characters
DEFAULT_OPTIONS
=
{
:domain
=>
nil
,
:path
=>
"/"
,
:expire_after
=>
nil
:key
=>
'_session_id'
,
:domain
=>
nil
,
:path
=>
"/"
,
:expire_after
=>
nil
,
:httponly
=>
false
}.
freeze
ENV_SESSION_KEY
=
"rack.session"
.
freeze
...
...
@@ -56,6 +58,18 @@ class CookieOverflow < StandardError; end
def
initialize
(
app
,
options
=
{})
options
=
options
.
dup
# Process legacy CGI options
options
=
options
.
symbolize_keys
if
options
.
has_key?
(
:session_path
)
options
[
:path
]
=
options
.
delete
(
:session_path
)
end
if
options
.
has_key?
(
:session_key
)
options
[
:key
]
=
options
.
delete
(
:session_key
)
end
if
options
.
has_key?
(
:session_http_only
)
options
[
:httponly
]
=
options
.
delete
(
:session_http_only
)
end
@app
=
app
# The session_key option is required.
...
...
actionpack/lib/action_controller/session_management.rb
浏览文件 @
2e22c7fd
...
...
@@ -6,35 +6,6 @@ def self.included(base)
end
end
class
Middleware
DEFAULT_OPTIONS
=
{
:path
=>
"/"
,
:key
=>
"_session_id"
,
:httponly
=>
true
,
}.
freeze
def
self
.
new
(
app
)
cgi_options
=
ActionController
::
Base
.
session_options
options
=
cgi_options
.
symbolize_keys
options
=
DEFAULT_OPTIONS
.
merge
(
options
)
if
options
.
has_key?
(
:session_path
)
options
[
:path
]
=
options
.
delete
(
:session_path
)
end
if
options
.
has_key?
(
:session_key
)
options
[
:key
]
=
options
.
delete
(
:session_key
)
end
if
options
.
has_key?
(
:session_http_only
)
options
[
:httponly
]
=
options
.
delete
(
:session_http_only
)
end
if
store
=
ActionController
::
Base
.
session_store
store
.
new
(
app
,
options
)
else
# Sessions disabled
lambda
{
|
env
|
app
.
call
(
env
)
}
end
end
end
module
ClassMethods
# Set the session store to be used for keeping the session data between requests.
# By default, sessions are stored in browser cookies (<tt>:cookie_store</tt>),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录