diff options
author | Valery Piashchynski <[email protected]> | 2021-06-03 20:02:18 +0300 |
---|---|---|
committer | GitHub <[email protected]> | 2021-06-03 20:02:18 +0300 |
commit | 0323e070103cc2c30d2cdfb12719d753acafe151 (patch) | |
tree | fd71da071040f22dab2fbca7d89fc8e4f92c81cf | |
parent | c3e57fd82d59be19b2c41479e9019c60a0afc28f (diff) | |
parent | 22e56524281c91aed3acaf5467be1de96798964b (diff) |
#702 fix(fcgi): use fcgi server in the `applyMiddlewares` for the `serveFCGI`
#702 fix(fcgi): use fcgi server in the `applyMiddlewares` for the `serveFCGI`
-rw-r--r-- | CHANGELOG.md | 15 | ||||
-rw-r--r-- | plugins/http/serve.go | 2 | ||||
-rw-r--r-- | tests/plugins/http/configs/.rr-fcgi-reqUri.yaml | 8 | ||||
-rw-r--r-- | tests/plugins/http/configs/.rr-fcgi.yaml | 18 | ||||
-rw-r--r-- | tests/plugins/http/configs/.rr-http-static.yaml | 4 | ||||
-rw-r--r-- | tests/plugins/http/http_plugin_test.go | 88 |
6 files changed, 106 insertions, 29 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 18cca954..5b9a9a7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,9 +6,9 @@ v2.3.0 (08.06.2021) ## 👀 New: -- ✏️ Brand new `broadcast` plugin now has the name - `websockets` with broadcast capabilities. It can handle - hundreds of thousands websocket connections very efficiently (~300k messages per second with 1k connected clients, - in-memory bus on 2CPU cores and 1GB of RAM) +- ✏️ Brand new `broadcast` plugin now has the name - `websockets` with broadcast capabilities. It can handle hundreds of + thousands websocket connections very efficiently (~300k messages per second with 1k connected clients, in-memory bus + on 2CPU cores and 1GB of RAM) - ✏️ Flatbuffers binary messages for the `websockets` RPC calls under the hood. - ✏️ Json-schemas for the config file v1.0 (it also registered in [schemastore.org](https://github.com/SchemaStore/schemastore/pull/1614)) @@ -18,8 +18,13 @@ v2.3.0 (08.06.2021) ## 🩹 Fixes: - 🐛 Fix: Bug with `informer.Workers` worked incorrectly: [Bug](https://github.com/spiral/roadrunner/issues/686) -- 🐛 Fix: Internal error messages will not be shown to the user (except HTTP status code). Error message will be in logs: [Bug](https://github.com/spiral/roadrunner/issues/659) -- 🐛 Fix: Error message will be properly shown in the log in case of `SoftJob` error: [Bug](https://github.com/spiral/roadrunner/issues/691) +- 🐛 Fix: Internal error messages will not be shown to the user (except HTTP status code). Error message will be in + logs: [Bug](https://github.com/spiral/roadrunner/issues/659) +- 🐛 Fix: Error message will be properly shown in the log in case of `SoftJob` + error: [Bug](https://github.com/spiral/roadrunner/issues/691) +- 🐛 Fix: Wrong applied middlewares for the `fcgi` server leads to the + NPE: [Bug](https://github.com/spiral/roadrunner/issues/701) + --- v2.2.1 (13.05.2021) diff --git a/plugins/http/serve.go b/plugins/http/serve.go index bf1ccafe..6d3f2228 100644 --- a/plugins/http/serve.go +++ b/plugins/http/serve.go @@ -73,7 +73,7 @@ func (p *Plugin) serveFCGI(errCh chan error) { const op = errors.Op("serveFCGI") if len(p.mdwr) > 0 { - applyMiddlewares(p.https, p.mdwr, p.cfg.Middleware, p.log) + applyMiddlewares(p.fcgi, p.mdwr, p.cfg.Middleware, p.log) } l, err := utils.CreateListener(p.cfg.FCGIConfig.Address) diff --git a/tests/plugins/http/configs/.rr-fcgi-reqUri.yaml b/tests/plugins/http/configs/.rr-fcgi-reqUri.yaml index 28c70c6f..cbdd211e 100644 --- a/tests/plugins/http/configs/.rr-fcgi-reqUri.yaml +++ b/tests/plugins/http/configs/.rr-fcgi-reqUri.yaml @@ -1,16 +1,12 @@ server: command: "php ../../http/client.php request-uri pipes" - user: "" - group: "" - env: - "RR_HTTP": "true" relay: "pipes" relay_timeout: "20s" http: address: :8082 max_request_size: 1024 - middleware: [ "" ] + middleware: [ ] uploads: forbid: [ ".php", ".exe", ".bat" ] trusted_subnets: [ "10.0.0.0/8", "127.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "::1/128", "fc00::/7", "fe80::/10" ] @@ -33,4 +29,4 @@ http: maxConcurrentStreams: 128 logs: mode: development - level: error
\ No newline at end of file + level: error diff --git a/tests/plugins/http/configs/.rr-fcgi.yaml b/tests/plugins/http/configs/.rr-fcgi.yaml index c749e42b..b0060d85 100644 --- a/tests/plugins/http/configs/.rr-fcgi.yaml +++ b/tests/plugins/http/configs/.rr-fcgi.yaml @@ -1,16 +1,16 @@ server: command: "php ../../http/client.php echo pipes" - user: "" - group: "" - env: - "RR_HTTP": "true" relay: "pipes" relay_timeout: "20s" http: address: :8081 max_request_size: 1024 - middleware: [ "" ] + middleware: [ "gzip" ] + static: + dir: "../../../tests" + forbid: [ "" ] + allow: [ ".txt", ".php" ] uploads: forbid: [ ".php", ".exe", ".bat" ] trusted_subnets: [ "10.0.0.0/8", "127.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "::1/128", "fc00::/7", "fe80::/10" ] @@ -20,12 +20,6 @@ http: allocate_timeout: 60s destroy_timeout: 60s - ssl: - address: :8889 - redirect: false - cert: fixtures/server.crt - key: fixtures/server.key - # root_ca: root.crt fcgi: address: tcp://0.0.0.0:6920 http2: @@ -33,4 +27,4 @@ http: maxConcurrentStreams: 128 logs: mode: development - level: error
\ No newline at end of file + level: error diff --git a/tests/plugins/http/configs/.rr-http-static.yaml b/tests/plugins/http/configs/.rr-http-static.yaml index e2e3af2a..30bb5b1e 100644 --- a/tests/plugins/http/configs/.rr-http-static.yaml +++ b/tests/plugins/http/configs/.rr-http-static.yaml @@ -1,9 +1,5 @@ server: command: "php ../../http/client.php pid pipes" - user: "" - group: "" - env: - "RR_HTTP": "true" relay: "pipes" relay_timeout: "20s" diff --git a/tests/plugins/http/http_plugin_test.go b/tests/plugins/http/http_plugin_test.go index a1fc94ec..fcedb943 100644 --- a/tests/plugins/http/http_plugin_test.go +++ b/tests/plugins/http/http_plugin_test.go @@ -364,7 +364,7 @@ func TestSSL(t *testing.T) { time.Sleep(time.Second * 1) t.Run("SSLEcho", sslEcho) t.Run("SSLNoRedirect", sslNoRedirect) - t.Run("fCGIecho", fcgiEcho) + t.Run("FCGEcho", fcgiEcho) stopCh <- struct{}{} wg.Wait() @@ -616,6 +616,92 @@ func sslPush(t *testing.T) { } } +func TestFastCGI_Echo(t *testing.T) { + cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.ErrorLevel)) + assert.NoError(t, err) + + cfg := &config.Viper{ + Path: "configs/.rr-fcgi.yaml", + Prefix: "rr", + } + + err = cont.RegisterAll( + cfg, + &logger.ZapLogger{}, + &server.Plugin{}, + &httpPlugin.Plugin{}, + &static.Plugin{}, + ) + assert.NoError(t, err) + + err = cont.Init() + if err != nil { + t.Fatal(err) + } + + ch, err := cont.Serve() + assert.NoError(t, err) + + sig := make(chan os.Signal, 1) + signal.Notify(sig, os.Interrupt, syscall.SIGINT, syscall.SIGTERM) + + wg := &sync.WaitGroup{} + wg.Add(1) + + stopCh := make(chan struct{}, 1) + + go func() { + defer wg.Done() + for { + select { + case e := <-ch: + assert.Fail(t, "error", e.Error.Error()) + err = cont.Stop() + if err != nil { + assert.FailNow(t, "error", err.Error()) + } + case <-sig: + err = cont.Stop() + if err != nil { + assert.FailNow(t, "error", err.Error()) + } + return + case <-stopCh: + // timeout + err = cont.Stop() + if err != nil { + assert.FailNow(t, "error", err.Error()) + } + return + } + } + }() + + time.Sleep(time.Second * 1) + t.Run("FastCGIEcho", fcgiEcho1) + + stopCh <- struct{}{} + wg.Wait() +} + +func fcgiEcho1(t *testing.T) { + time.Sleep(time.Second * 2) + fcgiConnFactory := gofast.SimpleConnFactory("tcp", "127.0.0.1:6920") + + fcgiHandler := gofast.NewHandler( + gofast.BasicParamsMap(gofast.BasicSession), + gofast.SimpleClientFactory(fcgiConnFactory), + ) + + w := httptest.NewRecorder() + req := httptest.NewRequest("GET", "http://site.local/hello-world", nil) + fcgiHandler.ServeHTTP(w, req) + + _, err := ioutil.ReadAll(w.Result().Body) //nolint:bodyclose + assert.NoError(t, err) + assert.Equal(t, 201, w.Result().StatusCode) //nolint:bodyclose +} + func TestFastCGI_RequestUri(t *testing.T) { cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.ErrorLevel)) assert.NoError(t, err) |