summaryrefslogtreecommitdiff
path: root/plugins/http/tests/plugin_middleware.go
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2020-11-25 21:56:26 +0300
committerValery Piashchynski <[email protected]>2020-11-25 21:56:26 +0300
commit1b0b033bcf4969e401b0c34b82171aa0b60b12cf (patch)
tree9cfe13b67613e69140bf29d320a1754cf2f7c9b7 /plugins/http/tests/plugin_middleware.go
parent2918cfca6d9579125257bfc9f5655537a63ec82a (diff)
Add mock logger, test for errors in log
Diffstat (limited to 'plugins/http/tests/plugin_middleware.go')
-rw-r--r--plugins/http/tests/plugin_middleware.go61
1 files changed, 61 insertions, 0 deletions
diff --git a/plugins/http/tests/plugin_middleware.go b/plugins/http/tests/plugin_middleware.go
new file mode 100644
index 00000000..de829d34
--- /dev/null
+++ b/plugins/http/tests/plugin_middleware.go
@@ -0,0 +1,61 @@
+package tests
+
+import (
+ "net/http"
+
+ "github.com/spiral/roadrunner/v2/plugins/config"
+)
+
+type PluginMiddleware struct {
+ config config.Configurer
+}
+
+func (p *PluginMiddleware) Init(cfg config.Configurer) error {
+ p.config = cfg
+ return nil
+}
+
+func (p *PluginMiddleware) Middleware(next http.Handler) http.HandlerFunc {
+ return func(w http.ResponseWriter, r *http.Request) {
+ if r.URL.Path == "/halt" {
+ w.WriteHeader(500)
+ _, err := w.Write([]byte("halted"))
+ if err != nil {
+ panic("error writing the data to the http reply")
+ }
+ } else {
+ next.ServeHTTP(w, r)
+ }
+ }
+}
+
+func (p *PluginMiddleware) Name() string {
+ return "pluginMiddleware"
+}
+
+type PluginMiddleware2 struct {
+ config config.Configurer
+}
+
+func (p *PluginMiddleware2) Init(cfg config.Configurer) error {
+ p.config = cfg
+ return nil
+}
+
+func (p *PluginMiddleware2) Middleware(next http.Handler) http.HandlerFunc {
+ return func(w http.ResponseWriter, r *http.Request) {
+ if r.URL.Path == "/boom" {
+ w.WriteHeader(555)
+ _, err := w.Write([]byte("boom"))
+ if err != nil {
+ panic("error writing the data to the http reply")
+ }
+ } else {
+ next.ServeHTTP(w, r)
+ }
+ }
+}
+
+func (p *PluginMiddleware2) Name() string {
+ return "pluginMiddleware2"
+}