summaryrefslogtreecommitdiff
path: root/plugins/websockets/validator
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-05-29 00:24:30 +0300
committerValery Piashchynski <[email protected]>2021-05-29 00:24:30 +0300
commitfcda08498e8f914bbd0798da898818cd5d0e4348 (patch)
tree62d88384d07997e2373f3b273ba0cb83569ebced /plugins/websockets/validator
parent8f13eb958c7eec49acba6e343edb77c6ede89f09 (diff)
- Add new internal plugin - channel. Which used to deliver messages from
the ws plugin to the http directly Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'plugins/websockets/validator')
-rw-r--r--plugins/websockets/validator/access_validator.go39
1 files changed, 33 insertions, 6 deletions
diff --git a/plugins/websockets/validator/access_validator.go b/plugins/websockets/validator/access_validator.go
index 9d9522d4..e3fde3d0 100644
--- a/plugins/websockets/validator/access_validator.go
+++ b/plugins/websockets/validator/access_validator.go
@@ -6,6 +6,7 @@ import (
"net/http"
"strings"
+ "github.com/spiral/roadrunner/v2/plugins/channel"
"github.com/spiral/roadrunner/v2/plugins/http/attributes"
)
@@ -67,16 +68,29 @@ func (w *AccessValidator) Error() string {
// AssertServerAccess checks if user can join server and returns error and body if user can not. Must return nil in
// case of error
-func (w *AccessValidator) AssertServerAccess(f http.HandlerFunc, r *http.Request) error {
+func (w *AccessValidator) AssertServerAccess(hub channel.Hub, r *http.Request) error {
if err := attributes.Set(r, "ws:joinServer", true); err != nil {
return err
}
defer delete(attributes.All(r), "ws:joinServer")
- f(w, r)
+ hub.ReceiveCh() <- struct {
+ RW http.ResponseWriter
+ Req *http.Request
+ }{
+ w,
+ r,
+ }
+
+ resp := <-hub.SendCh()
+
+ rmsg := resp.(struct {
+ RW http.ResponseWriter
+ Req *http.Request
+ })
- if !w.IsOK() {
+ if !rmsg.RW.(*AccessValidator).IsOK() {
return w
}
@@ -85,16 +99,29 @@ func (w *AccessValidator) AssertServerAccess(f http.HandlerFunc, r *http.Request
// AssertTopicsAccess checks if user can access given upstream, the application will receive all user headers and cookies.
// the decision to authorize user will be based on response code (200).
-func (w *AccessValidator) AssertTopicsAccess(f http.HandlerFunc, r *http.Request, channels ...string) error {
+func (w *AccessValidator) AssertTopicsAccess(hub channel.Hub, r *http.Request, channels ...string) error {
if err := attributes.Set(r, "ws:joinTopics", strings.Join(channels, ",")); err != nil {
return err
}
defer delete(attributes.All(r), "ws:joinTopics")
- f(w, r)
+ hub.ReceiveCh() <- struct {
+ RW http.ResponseWriter
+ Req *http.Request
+ }{
+ w,
+ r,
+ }
+
+ resp := <-hub.SendCh()
+
+ rmsg := resp.(struct {
+ RW http.ResponseWriter
+ Req *http.Request
+ })
- if !w.IsOK() {
+ if !rmsg.RW.(*AccessValidator).IsOK() {
return w
}