summaryrefslogtreecommitdiff
path: root/plugins/websockets/validator/access_validator.go
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-09-16 21:46:50 +0300
committerGitHub <[email protected]>2021-09-16 21:46:50 +0300
commit3581b45f237a3f7aa29591ceb2bf6f4a4642a2f5 (patch)
treee723b19ec1ac16b7ccc7b3c2da69d4a416d63d81 /plugins/websockets/validator/access_validator.go
parent337d292dd2d6ff0a555098b1970d8194d8df8bc2 (diff)
parent823d831b57b75f70c7c3bbbee355f2016633bb3b (diff)
[#803]: feat(plugins): move plugins to a separate repositoryv2.5.0-alpha.2
[#803]: feat(plugins): move plugins to a separate repository
Diffstat (limited to 'plugins/websockets/validator/access_validator.go')
-rw-r--r--plugins/websockets/validator/access_validator.go81
1 files changed, 0 insertions, 81 deletions
diff --git a/plugins/websockets/validator/access_validator.go b/plugins/websockets/validator/access_validator.go
deleted file mode 100644
index 2685da7f..00000000
--- a/plugins/websockets/validator/access_validator.go
+++ /dev/null
@@ -1,81 +0,0 @@
-package validator
-
-import (
- "net/http"
- "strings"
-
- json "github.com/json-iterator/go"
- "github.com/spiral/errors"
- handler "github.com/spiral/roadrunner/v2/pkg/worker_handler"
- "github.com/spiral/roadrunner/v2/plugins/http/attributes"
-)
-
-type AccessValidatorFn = func(r *http.Request, channels ...string) (*AccessValidator, error)
-
-const (
- joinServer string = "ws:joinServer"
- joinTopics string = "ws:joinTopics"
-)
-
-type AccessValidator struct {
- Header http.Header `json:"headers"`
- Status int `json:"status"`
- Body []byte
-}
-
-func ServerAccessValidator(r *http.Request) ([]byte, error) {
- const op = errors.Op("server_access_validator")
-
- err := attributes.Set(r, "ws:joinServer", true)
- if err != nil {
- return nil, errors.E(op, err)
- }
-
- defer delete(attributes.All(r), joinServer)
-
- req := &handler.Request{
- RemoteAddr: handler.FetchIP(r.RemoteAddr),
- Protocol: r.Proto,
- Method: r.Method,
- URI: handler.URI(r),
- Header: r.Header,
- Cookies: make(map[string]string),
- RawQuery: r.URL.RawQuery,
- Attributes: attributes.All(r),
- }
-
- data, err := json.Marshal(req)
- if err != nil {
- return nil, errors.E(op, err)
- }
-
- return data, nil
-}
-
-func TopicsAccessValidator(r *http.Request, topics ...string) ([]byte, error) {
- const op = errors.Op("topic_access_validator")
- err := attributes.Set(r, "ws:joinTopics", strings.Join(topics, ","))
- if err != nil {
- return nil, errors.E(op, err)
- }
-
- defer delete(attributes.All(r), joinTopics)
-
- req := &handler.Request{
- RemoteAddr: handler.FetchIP(r.RemoteAddr),
- Protocol: r.Proto,
- Method: r.Method,
- URI: handler.URI(r),
- Header: r.Header,
- Cookies: make(map[string]string),
- RawQuery: r.URL.RawQuery,
- Attributes: attributes.All(r),
- }
-
- data, err := json.Marshal(req)
- if err != nil {
- return nil, errors.E(op, err)
- }
-
- return data, nil
-}