summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-01-21 16:08:06 +0300
committerValery Piashchynski <[email protected]>2021-01-21 16:08:06 +0300
commit8029e2d1107e4663f1104ebf25c40f252c8ea111 (patch)
tree7c9a6744fa9ce130d80c634da3d7596f70fda51a
parent7da6c78449776e1f3c6716250bca0b712a0423a4 (diff)
Fix headers configs
Update rr.yaml Remove previous stderr messages when they were sent
-rwxr-xr-x.rr.yaml13
-rwxr-xr-xpkg/worker/worker.go4
-rw-r--r--plugins/headers/config.go14
-rw-r--r--plugins/headers/plugin.go6
-rw-r--r--tests/plugins/headers/configs/.rr-cors-headers.yaml16
-rw-r--r--tests/plugins/headers/configs/.rr-headers-init.yaml16
-rw-r--r--tests/plugins/headers/configs/.rr-req-headers.yaml4
-rw-r--r--tests/plugins/headers/configs/.rr-res-headers.yaml4
-rw-r--r--tests/psr-worker-bench.php1
9 files changed, 48 insertions, 30 deletions
diff --git a/.rr.yaml b/.rr.yaml
index 2985dee7..ca638aa9 100755
--- a/.rr.yaml
+++ b/.rr.yaml
@@ -31,6 +31,19 @@ http:
"fc00::/7",
"fe80::/10",
]
+ headers:
+ cors:
+ allowed_origin: "*"
+ allowed_headers: "*"
+ allowed_methods: "GET,POST,PUT,DELETE"
+ allow_credentials: true
+ exposed_headers: "Cache-Control,Content-Language,Content-Type,Expires,Last-Modified,Pragma"
+ max_age: 600
+ request:
+ input: "custom-header"
+ response:
+ output: "output-header"
+
static:
dir: "tests"
forbid: [ "" ]
diff --git a/pkg/worker/worker.go b/pkg/worker/worker.go
index 4d4ca09b..bf70d646 100755
--- a/pkg/worker/worker.go
+++ b/pkg/worker/worker.go
@@ -79,6 +79,7 @@ type Process struct {
// InitBaseWorker creates new Process over given exec.cmd.
func InitBaseWorker(cmd *exec.Cmd, options ...Options) (worker.BaseProcess, error) {
+ const op = errors.Op("init_base_worker")
if cmd.Process != nil {
return nil, fmt.Errorf("can't attach to running process")
}
@@ -307,9 +308,10 @@ func (w *Process) watch() {
n, _ := w.rd.Read(*buf)
w.events.Push(events.WorkerEvent{Event: events.EventWorkerLog, Worker: w, Payload: (*buf)[:n]})
w.mu.Lock()
+ // delete all prev messages
+ w.stderr.Reset()
// write new message
w.stderr.Write((*buf)[:n])
- w.stderr.Reset()
w.mu.Unlock()
w.put(buf)
}
diff --git a/plugins/headers/config.go b/plugins/headers/config.go
index 8d4e29c2..688b4764 100644
--- a/plugins/headers/config.go
+++ b/plugins/headers/config.go
@@ -2,7 +2,7 @@ package headers
// Config declares headers service configuration.
type Config struct {
- Headers struct {
+ Headers *struct {
// CORS settings.
CORS *CORSConfig
@@ -17,20 +17,20 @@ type Config struct {
// CORSConfig headers configuration.
type CORSConfig struct {
// AllowedOrigin: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin
- AllowedOrigin string
+ AllowedOrigin string `mapstructure:"allowed_origin"`
// AllowedHeaders: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers
- AllowedHeaders string
+ AllowedHeaders string `mapstructure:"allowed_headers"`
// AllowedMethods: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Methods
- AllowedMethods string
+ AllowedMethods string `mapstructure:"allowed_methods"`
// AllowCredentials https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Credentials
- AllowCredentials *bool
+ AllowCredentials *bool `mapstructure:"allow_credentials"`
// ExposeHeaders: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Expose-Headers
- ExposedHeaders string
+ ExposedHeaders string `mapstructure:"exposed_headers"`
// MaxAge of CORS headers in seconds/
- MaxAge int
+ MaxAge int `mapstructure:"max_age"`
}
diff --git a/plugins/headers/plugin.go b/plugins/headers/plugin.go
index 84194d7e..a5ee702f 100644
--- a/plugins/headers/plugin.go
+++ b/plugins/headers/plugin.go
@@ -22,7 +22,7 @@ type Plugin struct {
// misconfiguration. Services must not be used without proper configuration pushed first.
func (s *Plugin) Init(cfg config.Configurer) error {
const op = errors.Op("headers_plugin_init")
- if !cfg.Has(PluginName) {
+ if !cfg.Has(RootPluginName) {
return errors.E(op, errors.Disabled)
}
err := cfg.UnmarshalKey(RootPluginName, &s.cfg)
@@ -30,6 +30,10 @@ func (s *Plugin) Init(cfg config.Configurer) error {
return errors.E(op, errors.Disabled, err)
}
+ if s.cfg.Headers == nil {
+ return errors.E(op, errors.Disabled)
+ }
+
return nil
}
diff --git a/tests/plugins/headers/configs/.rr-cors-headers.yaml b/tests/plugins/headers/configs/.rr-cors-headers.yaml
index c5ff576d..9d2ef7e5 100644
--- a/tests/plugins/headers/configs/.rr-cors-headers.yaml
+++ b/tests/plugins/headers/configs/.rr-cors-headers.yaml
@@ -17,16 +17,16 @@ http:
# Additional HTTP headers and CORS control.
headers:
cors:
- allowedOrigin: "*"
- allowedHeaders: "*"
- allowedMethods: "GET,POST,PUT,DELETE"
- allowCredentials: true
- exposedHeaders: "Cache-Control,Content-Language,Content-Type,Expires,Last-Modified,Pragma"
- maxAge: 600
+ allowed_origin: "*"
+ allowed_headers: "*"
+ allowed_methods: "GET,POST,PUT,DELETE"
+ allow_credentials: true
+ exposed_headers: "Cache-Control,Content-Language,Content-Type,Expires,Last-Modified,Pragma"
+ max_age: 600
request:
- "input": "custom-header"
+ input: "custom-header"
response:
- "output": "output-header"
+ output: "output-header"
pool:
num_workers: 2
max_jobs: 0
diff --git a/tests/plugins/headers/configs/.rr-headers-init.yaml b/tests/plugins/headers/configs/.rr-headers-init.yaml
index 059df9ac..b2781f2b 100644
--- a/tests/plugins/headers/configs/.rr-headers-init.yaml
+++ b/tests/plugins/headers/configs/.rr-headers-init.yaml
@@ -17,16 +17,16 @@ http:
# Additional HTTP headers and CORS control.
headers:
cors:
- allowedOrigin: "*"
- allowedHeaders: "*"
- allowedMethods: "GET,POST,PUT,DELETE"
- allowCredentials: true
- exposedHeaders: "Cache-Control,Content-Language,Content-Type,Expires,Last-Modified,Pragma"
- maxAge: 600
+ allowed_origin: "*"
+ allowed_headers: "*"
+ allowed_methods: "GET,POST,PUT,DELETE"
+ allow_credentials: true
+ exposed_headers: "Cache-Control,Content-Language,Content-Type,Expires,Last-Modified,Pragma"
+ max_age: 600
request:
- "Example-Request-Header": "Value"
+ Example-Request-Header: "Value"
response:
- "X-Powered-By": "RoadRunner"
+ X-Powered-By: "RoadRunner"
pool:
num_workers: 2
max_jobs: 0
diff --git a/tests/plugins/headers/configs/.rr-req-headers.yaml b/tests/plugins/headers/configs/.rr-req-headers.yaml
index f0a52e17..a2b97171 100644
--- a/tests/plugins/headers/configs/.rr-req-headers.yaml
+++ b/tests/plugins/headers/configs/.rr-req-headers.yaml
@@ -17,9 +17,9 @@ http:
# Additional HTTP headers and CORS control.
headers:
request:
- "input": "custom-header"
+ input: "custom-header"
response:
- "output": "output-header"
+ output: "output-header"
pool:
num_workers: 2
max_jobs: 0
diff --git a/tests/plugins/headers/configs/.rr-res-headers.yaml b/tests/plugins/headers/configs/.rr-res-headers.yaml
index 868b9746..4448343c 100644
--- a/tests/plugins/headers/configs/.rr-res-headers.yaml
+++ b/tests/plugins/headers/configs/.rr-res-headers.yaml
@@ -17,9 +17,9 @@ http:
# Additional HTTP headers and CORS control.
headers:
request:
- "input": "custom-header"
+ input: "custom-header"
response:
- "output": "output-header"
+ output: "output-header"
pool:
num_workers: 2
max_jobs: 0
diff --git a/tests/psr-worker-bench.php b/tests/psr-worker-bench.php
index 3f6408bf..d382098a 100644
--- a/tests/psr-worker-bench.php
+++ b/tests/psr-worker-bench.php
@@ -17,7 +17,6 @@ while ($req = $worker->waitRequest()) {
try {
$rsp = new \Nyholm\Psr7\Response();
$rsp->getBody()->write("hello world");
- error_log("hello");
$worker->respond($rsp);
} catch (\Throwable $e) {
$worker->getWorker()->error((string)$e);