Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
a9fde9a2
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,发现更多精彩内容 >>
提交
a9fde9a2
编写于
12月 18, 2008
作者:
J
Joshua Peek
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Cleanup dispatch path
上级
3b35366d
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
16 addition
and
24 deletion
+16
-24
actionpack/lib/action_controller/dispatcher.rb
actionpack/lib/action_controller/dispatcher.rb
+9
-18
actionpack/lib/action_controller/rack_process.rb
actionpack/lib/action_controller/rack_process.rb
+1
-2
actionpack/test/controller/dispatcher_test.rb
actionpack/test/controller/dispatcher_test.rb
+3
-1
actionpack/test/controller/rack_test.rb
actionpack/test/controller/rack_test.rb
+3
-3
未找到文件。
actionpack/lib/action_controller/dispatcher.rb
浏览文件 @
a9fde9a2
...
...
@@ -65,18 +65,23 @@ def to_prepare(identifier = nil, &block)
include
ActiveSupport
::
Callbacks
define_callbacks
:prepare_dispatch
,
:before_dispatch
,
:after_dispatch
# DEPRECATE: Remove arguments
# DEPRECATE: Remove arguments
, since they are only used by CGI
def
initialize
(
output
=
$stdout
,
request
=
nil
,
response
=
nil
)
@output
,
@request
,
@response
=
output
,
request
,
response
@output
=
output
@app
=
@@middleware
.
build
(
lambda
{
|
env
|
self
.
dup
.
_call
(
env
)
})
end
def
dispatch
begin
run_callbacks
:before_dispatch
handle_request
controller
=
Routing
::
Routes
.
recognize
(
@request
)
controller
.
process
(
@request
,
@response
).
to_a
rescue
Exception
=>
exception
failsafe_rescue
exception
if
controller
||=
(
::
ApplicationController
rescue
Base
)
controller
.
process_with_exception
(
@request
,
@response
,
exception
).
to_a
else
raise
exception
end
ensure
run_callbacks
:after_dispatch
,
:enumerator
=>
:reverse_each
end
...
...
@@ -123,19 +128,5 @@ def checkin_connections
return
if
@request
.
key?
(
"rack.test"
)
ActiveRecord
::
Base
.
clear_active_connections!
end
protected
def
handle_request
@controller
=
Routing
::
Routes
.
recognize
(
@request
)
@controller
.
process
(
@request
,
@response
).
out
end
def
failsafe_rescue
(
exception
)
if
@controller
||=
(
::
ApplicationController
rescue
Base
)
@controller
.
process_with_exception
(
@request
,
@response
,
exception
).
out
else
raise
exception
end
end
end
end
actionpack/lib/action_controller/rack_process.rb
浏览文件 @
a9fde9a2
...
...
@@ -83,7 +83,7 @@ def status
@status
||
super
end
def
out
(
&
block
)
def
to_a
(
&
block
)
@block
=
block
@status
=
headers
.
delete
(
"Status"
)
if
[
204
,
304
].
include?
(
status
.
to_i
)
...
...
@@ -93,7 +93,6 @@ def out(&block)
[
status
,
headers
.
to_hash
,
self
]
end
end
alias
to_a
out
def
each
(
&
callback
)
if
@body
.
respond_to?
(
:call
)
...
...
actionpack/test/controller/dispatcher_test.rb
浏览文件 @
a9fde9a2
...
...
@@ -96,7 +96,9 @@ def test_to_prepare_with_identifier_replaces
private
def
dispatch
(
cache_classes
=
true
)
Dispatcher
.
any_instance
.
stubs
(
:handle_request
).
returns
([
200
,
{},
'response'
])
controller
=
mock
()
controller
.
stubs
(
:process
).
returns
([
200
,
{},
'response'
])
ActionController
::
Routing
::
Routes
.
stubs
(
:recognize
).
returns
(
controller
)
Dispatcher
.
define_dispatcher_callbacks
(
cache_classes
)
@dispatcher
.
call
({})
end
...
...
actionpack/test/controller/rack_test.rb
浏览文件 @
a9fde9a2
...
...
@@ -236,7 +236,7 @@ def test_simple_output
@response
.
body
=
"Hello, World!"
@response
.
prepare!
status
,
headers
,
body
=
@response
.
out
status
,
headers
,
body
=
@response
.
to_a
assert_equal
"200 OK"
,
status
assert_equal
({
"Content-Type"
=>
"text/html; charset=utf-8"
,
...
...
@@ -257,7 +257,7 @@ def test_streaming_block
end
@response
.
prepare!
status
,
headers
,
body
=
@response
.
out
status
,
headers
,
body
=
@response
.
to_a
assert_equal
"200 OK"
,
status
assert_equal
({
"Content-Type"
=>
"text/html; charset=utf-8"
,
"Cache-Control"
=>
"no-cache"
,
"Set-Cookie"
=>
[]},
headers
)
...
...
@@ -293,6 +293,6 @@ def test_status
private
def
response_headers
@response
.
prepare!
@response
.
out
[
1
]
@response
.
to_a
[
1
]
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录