Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
d9816546
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,发现更多精彩内容 >>
未验证
提交
d9816546
编写于
12月 05, 2018
作者:
R
Rafael França
提交者:
GitHub
12月 05, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #34194 from staugaard/staugaard/actioncable_unauthorized
Stop trying to reconnect on unauthorized cable connections
上级
884310fd
58dbc1c2
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
46 addition
and
10 deletion
+46
-10
actioncable/CHANGELOG.md
actioncable/CHANGELOG.md
+5
-0
actioncable/app/assets/javascripts/action_cable.js
actioncable/app/assets/javascripts/action_cable.js
+13
-1
actioncable/app/javascript/action_cable/connection.js
actioncable/app/javascript/action_cable/connection.js
+4
-1
actioncable/lib/action_cable.rb
actioncable/lib/action_cable.rb
+6
-0
actioncable/lib/action_cable/connection/base.rb
actioncable/lib/action_cable/connection/base.rb
+8
-3
actioncable/lib/action_cable/server/base.rb
actioncable/lib/action_cable/server/base.rb
+3
-1
actioncable/test/connection/authorization_test.rb
actioncable/test/connection/authorization_test.rb
+5
-2
actioncable/test/connection/base_test.rb
actioncable/test/connection/base_test.rb
+1
-1
actioncable/test/connection/client_socket_test.rb
actioncable/test/connection/client_socket_test.rb
+1
-1
未找到文件。
actioncable/CHANGELOG.md
浏览文件 @
d9816546
*
The JavaScript WebSocket client will no longer try to reconnect
when you call
`reject_unauthorized_connection`
on the connection.
*Mick Staugaard*
*
`ActionCable.Connection#getState`
now references the configurable
`ActionCable.adapters.WebSocket`
property rather than the
`WebSocket`
global
variable, matching the behavior of
`ActionCable.Connection#open`
.
...
...
actioncable/app/assets/javascripts/action_cable.js
浏览文件 @
d9816546
...
...
@@ -136,10 +136,16 @@
var
INTERNAL
=
{
message_types
:
{
welcome
:
"
welcome
"
,
disconnect
:
"
disconnect
"
,
ping
:
"
ping
"
,
confirmation
:
"
confirm_subscription
"
,
rejection
:
"
reject_subscription
"
},
disconnect_reasons
:
{
unauthorized
:
"
unauthorized
"
,
invalid_request
:
"
invalid_request
"
,
server_restart
:
"
server_restart
"
},
default_mount_path
:
"
/cable
"
,
protocols
:
[
"
actioncable-v1-json
"
,
"
actioncable-unsupported
"
]
};
...
...
@@ -251,12 +257,18 @@
if
(
!
this
.
isProtocolSupported
())
{
return
;
}
var
_JSON$parse
=
JSON
.
parse
(
event
.
data
),
identifier
=
_JSON$parse
.
identifier
,
message
=
_JSON$parse
.
message
,
type
=
_JSON$parse
.
type
;
var
_JSON$parse
=
JSON
.
parse
(
event
.
data
),
identifier
=
_JSON$parse
.
identifier
,
message
=
_JSON$parse
.
message
,
reason
=
_JSON$parse
.
reason
,
reconnect
=
_JSON$parse
.
reconnect
,
type
=
_JSON$parse
.
type
;
switch
(
type
)
{
case
message_types
.
welcome
:
this
.
monitor
.
recordConnect
();
return
this
.
subscriptions
.
reload
();
case
message_types
.
disconnect
:
logger
.
log
(
"
Disconnecting. Reason:
"
+
reason
);
return
this
.
close
({
allowReconnect
:
reconnect
});
case
message_types
.
ping
:
return
this
.
monitor
.
recordPing
();
...
...
actioncable/app/javascript/action_cable/connection.js
浏览文件 @
d9816546
...
...
@@ -117,11 +117,14 @@ Connection.reopenDelay = 500
Connection
.
prototype
.
events
=
{
message
(
event
)
{
if
(
!
this
.
isProtocolSupported
())
{
return
}
const
{
identifier
,
message
,
type
}
=
JSON
.
parse
(
event
.
data
)
const
{
identifier
,
message
,
reason
,
reconnect
,
type
}
=
JSON
.
parse
(
event
.
data
)
switch
(
type
)
{
case
message_types
.
welcome
:
this
.
monitor
.
recordConnect
()
return
this
.
subscriptions
.
reload
()
case
message_types
.
disconnect
:
logger
.
log
(
`Disconnecting. Reason:
${
reason
}
`
)
return
this
.
close
({
allowReconnect
:
reconnect
})
case
message_types
.
ping
:
return
this
.
monitor
.
recordPing
()
case
message_types
.
confirmation
:
...
...
actioncable/lib/action_cable.rb
浏览文件 @
d9816546
...
...
@@ -33,10 +33,16 @@ module ActionCable
INTERNAL
=
{
message_types:
{
welcome:
"welcome"
,
disconnect:
"disconnect"
,
ping:
"ping"
,
confirmation:
"confirm_subscription"
,
rejection:
"reject_subscription"
},
disconnect_reasons:
{
unauthorized:
"unauthorized"
,
invalid_request:
"invalid_request"
,
server_restart:
"server_restart"
},
default_mount_path:
"/cable"
,
protocols:
[
"actioncable-v1-json"
,
"actioncable-unsupported"
].
freeze
}
...
...
actioncable/lib/action_cable/connection/base.rb
浏览文件 @
d9816546
...
...
@@ -95,7 +95,12 @@ def transmit(cable_message) # :nodoc:
end
# Close the WebSocket connection.
def
close
def
close
(
reason:
nil
,
reconnect:
true
)
transmit
(
type:
ActionCable
::
INTERNAL
[
:message_types
][
:disconnect
],
reason:
reason
,
reconnect:
reconnect
)
websocket
.
close
end
...
...
@@ -170,7 +175,7 @@ def handle_open
message_buffer
.
process!
server
.
add_connection
(
self
)
rescue
ActionCable
::
Connection
::
Authorization
::
UnauthorizedError
respond_to_invalid_request
close
(
reason:
ActionCable
::
INTERNAL
[
:disconnect_reasons
][
:unauthorized
],
reconnect:
false
)
if
websocket
.
alive?
end
def
handle_close
...
...
@@ -211,7 +216,7 @@ def respond_to_successful_request
end
def
respond_to_invalid_request
close
if
websocket
.
alive?
close
(
reason:
ActionCable
::
INTERNAL
[
:disconnect_reasons
][
:invalid_request
])
if
websocket
.
alive?
logger
.
error
invalid_request_message
logger
.
info
finished_request_message
...
...
actioncable/lib/action_cable/server/base.rb
浏览文件 @
d9816546
...
...
@@ -36,7 +36,9 @@ def disconnect(identifiers)
end
def
restart
connections
.
each
(
&
:close
)
connections
.
each
do
|
connection
|
connection
.
close
(
reason:
ActionCable
::
INTERNAL
[
:disconnect_reasons
][
:server_restart
])
end
@mutex
.
synchronize
do
# Shutdown the worker pool
...
...
actioncable/test/connection/authorization_test.rb
浏览文件 @
d9816546
...
...
@@ -25,8 +25,11 @@ def send_async(method, *args)
"HTTP_HOST"
=>
"localhost"
,
"HTTP_ORIGIN"
=>
"http://rubyonrails.com"
connection
=
Connection
.
new
(
server
,
env
)
assert_called
(
connection
.
websocket
,
:close
)
do
connection
.
process
assert_called_with
(
connection
.
websocket
,
:transmit
,
[{
type:
"disconnect"
,
reason:
"unauthorized"
,
reconnect:
false
}.
to_json
])
do
assert_called
(
connection
.
websocket
,
:close
)
do
connection
.
process
end
end
end
end
...
...
actioncable/test/connection/base_test.rb
浏览文件 @
d9816546
...
...
@@ -108,7 +108,7 @@ def send_async(method, *args)
connection
.
process
assert_called
(
connection
.
websocket
,
:close
)
do
connection
.
close
connection
.
close
(
reason:
"testing"
)
end
end
end
...
...
actioncable/test/connection/client_socket_test.rb
浏览文件 @
d9816546
...
...
@@ -58,7 +58,7 @@ def on_error(message)
client
.
instance_variable_get
(
"@stream"
)
.
instance_variable_get
(
"@rack_hijack_io"
)
.
define_singleton_method
(
:close
)
{
event
.
set
}
connection
.
close
connection
.
close
(
reason:
"testing"
)
event
.
wait
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录