diff options
author | Valery Piashchynski <[email protected]> | 2020-12-21 19:42:23 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2020-12-21 19:42:23 +0300 |
commit | ee8b4075c0f836d698d1ae505c87c17147de447a (patch) | |
tree | 531d980e5bfb94ee39b03952a97e0445f7955409 /plugins/gzip | |
parent | 0ad45031047bb479e06ce0a0f496c6db9b2641c9 (diff) |
Move plugins to the roadrunner-plugins repository
Diffstat (limited to 'plugins/gzip')
-rw-r--r-- | plugins/gzip/plugin.go | 25 | ||||
-rw-r--r-- | plugins/gzip/tests/configs/.rr-http-middlewareNotExist.yaml | 25 | ||||
-rw-r--r-- | plugins/gzip/tests/configs/.rr-http-withGzip.yaml | 25 | ||||
-rw-r--r-- | plugins/gzip/tests/plugin_test.go | 170 |
4 files changed, 0 insertions, 245 deletions
diff --git a/plugins/gzip/plugin.go b/plugins/gzip/plugin.go deleted file mode 100644 index e5b9e4f5..00000000 --- a/plugins/gzip/plugin.go +++ /dev/null @@ -1,25 +0,0 @@ -package gzip - -import ( - "net/http" - - "github.com/NYTimes/gziphandler" -) - -const PluginName = "gzip" - -type Gzip struct{} - -func (g *Gzip) Init() error { - return nil -} - -func (g *Gzip) Middleware(next http.Handler) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - gziphandler.GzipHandler(next).ServeHTTP(w, r) - } -} - -func (g *Gzip) Name() string { - return PluginName -} diff --git a/plugins/gzip/tests/configs/.rr-http-middlewareNotExist.yaml b/plugins/gzip/tests/configs/.rr-http-middlewareNotExist.yaml deleted file mode 100644 index 08c9b0ff..00000000 --- a/plugins/gzip/tests/configs/.rr-http-middlewareNotExist.yaml +++ /dev/null @@ -1,25 +0,0 @@ -server: - command: "php ../../../tests/psr-worker.php" - user: "" - group: "" - env: - "RR_HTTP": "true" - relay: "pipes" - relayTimeout: "20s" - -http: - debug: true - address: 127.0.0.1:18103 - maxRequestSize: 1024 - middleware: [ "gzip", "foo" ] - uploads: - forbid: [ ".php", ".exe", ".bat" ] - trustedSubnets: [ "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" ] - pool: - numWorkers: 2 - maxJobs: 0 - allocateTimeout: 60s - destroyTimeout: 60s -logs: - mode: development - level: error
\ No newline at end of file diff --git a/plugins/gzip/tests/configs/.rr-http-withGzip.yaml b/plugins/gzip/tests/configs/.rr-http-withGzip.yaml deleted file mode 100644 index 3475d5dd..00000000 --- a/plugins/gzip/tests/configs/.rr-http-withGzip.yaml +++ /dev/null @@ -1,25 +0,0 @@ -server: - command: "php ../../../tests/psr-worker.php" - user: "" - group: "" - env: - "RR_HTTP": "true" - relay: "pipes" - relayTimeout: "20s" - -http: - debug: true - address: 127.0.0.1:18953 - maxRequestSize: 1024 - middleware: [ "gzip" ] - uploads: - forbid: [ ".php", ".exe", ".bat" ] - trustedSubnets: [ "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" ] - pool: - numWorkers: 2 - maxJobs: 0 - allocateTimeout: 60s - destroyTimeout: 60s -logs: - mode: development - level: error
\ No newline at end of file diff --git a/plugins/gzip/tests/plugin_test.go b/plugins/gzip/tests/plugin_test.go deleted file mode 100644 index 97291ebe..00000000 --- a/plugins/gzip/tests/plugin_test.go +++ /dev/null @@ -1,170 +0,0 @@ -package tests - -import ( - "net/http" - "os" - "os/signal" - "sync" - "syscall" - "testing" - "time" - - "github.com/golang/mock/gomock" - "github.com/spiral/endure" - "github.com/spiral/roadrunner/v2/mocks" - "github.com/spiral/roadrunner/v2/plugins/config" - "github.com/spiral/roadrunner/v2/plugins/gzip" - httpPlugin "github.com/spiral/roadrunner/v2/plugins/http" - "github.com/spiral/roadrunner/v2/plugins/logger" - "github.com/spiral/roadrunner/v2/plugins/server" - "github.com/stretchr/testify/assert" -) - -func TestGzipPlugin(t *testing.T) { - cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.ErrorLevel)) - assert.NoError(t, err) - - cfg := &config.Viper{ - Path: "configs/.rr-http-withGzip.yaml", - Prefix: "rr", - } - - err = cont.RegisterAll( - cfg, - &logger.ZapLogger{}, - &server.Plugin{}, - &httpPlugin.Plugin{}, - &gzip.Gzip{}, - ) - 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) - - go func() { - tt := time.NewTimer(time.Second * 10) - 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 <-tt.C: - // timeout - err = cont.Stop() - if err != nil { - assert.FailNow(t, "error", err.Error()) - } - return - } - } - }() - - t.Run("GzipCheckHeader", headerCheck) - wg.Wait() -} - -func headerCheck(t *testing.T) { - req, err := http.NewRequest("GET", "http://localhost:18953", nil) - assert.NoError(t, err) - client := &http.Client{ - Transport: &http.Transport{ - DisableCompression: false, - }, - } - - r, err := client.Do(req) - assert.NoError(t, err) - assert.True(t, r.Uncompressed) - - err = r.Body.Close() - assert.NoError(t, err) -} - -func TestMiddlewareNotExist(t *testing.T) { - cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.ErrorLevel)) - assert.NoError(t, err) - - cfg := &config.Viper{ - Path: "configs/.rr-http-middlewareNotExist.yaml", - Prefix: "rr", - } - - controller := gomock.NewController(t) - mockLogger := mocks.NewMockLogger(controller) - - mockLogger.EXPECT().Warn("requested middleware does not exist", "requested", "foo") - - err = cont.RegisterAll( - cfg, - mockLogger, - &server.Plugin{}, - &httpPlugin.Plugin{}, - &gzip.Gzip{}, - ) - 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) - - go func() { - tt := time.NewTimer(time.Second * 5) - 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 <-tt.C: - // timeout - err = cont.Stop() - if err != nil { - assert.FailNow(t, "error", err.Error()) - } - return - } - } - }() - - wg.Wait() -} |