Skip to content
This repository was archived by the owner on Jul 1, 2021. It is now read-only.

Commit 3820273

Browse files
committed
- improved error handling
- RR_BROADCAST_URL renamed to RR_BROADCAST_PATH
1 parent dc8a206 commit 3820273

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

access_validator.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ func (w *accessValidator) Error() string {
6868
// case of error
6969
func (w *accessValidator) assertServerAccess(f http.HandlerFunc, r *http.Request) error {
7070
if err := attributes.Set(r, "ws:joinServer", true); err != nil {
71-
// return err
72-
// todo: need to update it
71+
return err
7372
}
7473

7574
defer delete(attributes.All(r), "ws:joinServer")
@@ -87,7 +86,7 @@ func (w *accessValidator) assertServerAccess(f http.HandlerFunc, r *http.Request
8786
// the decision to authorize user will be based on response code (200).
8887
func (w *accessValidator) assertTopicsAccess(f http.HandlerFunc, r *http.Request, channels ...string) error {
8988
if err := attributes.Set(r, "ws:joinTopics", strings.Join(channels, ",")); err != nil {
90-
return w
89+
return err
9190
}
9291

9392
defer delete(attributes.All(r), "ws:joinTopics")

service.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func (s *Service) Init(
5454

5555
if env != nil {
5656
// ensure that underlying kernel knows what route to handle
57-
env.SetEnv("RR_BROADCAST_URL", cfg.Path)
57+
env.SetEnv("RR_BROADCAST_PATH", cfg.Path)
5858
}
5959

6060
// init all this stuff
@@ -97,7 +97,11 @@ func (s *Service) middleware(f http.HandlerFunc) http.HandlerFunc {
9797
// checking server access
9898
if err := newValidator().assertServerAccess(f, r); err != nil {
9999
// show the error to the user
100-
err.(*accessValidator).copy(w)
100+
if av, ok := err.(*accessValidator); ok {
101+
av.copy(w)
102+
} else {
103+
w.WriteHeader(400)
104+
}
101105
return
102106
}
103107

tests/worker-ok.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
while ($req = $psr7->acceptRequest()) {
1111
try {
1212
$resp = new \Zend\Diactoros\Response();
13-
$resp->getBody()->write($_SERVER['RR_BROADCAST_URL'] ?? '');
13+
$resp->getBody()->write($_SERVER['RR_BROADCAST_PATH'] ?? '');
1414
$psr7->respond($resp);
1515
} catch (\Throwable $e) {
1616
$psr7->getWorker()->error((string)$e);

0 commit comments

Comments
 (0)