summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-04-28 14:10:27 +0300
committerValery Piashchynski <[email protected]>2021-04-28 14:10:27 +0300
commit30c25f17fa7d6386e33a4894c812f7ca5db990ad (patch)
tree03f53535addf71a81eca4b9a1d3ba29d4ebf4984
parent4cb2247f909d02c922edb6f8e3d3741cc5a2c077 (diff)
- Fix middleware order
- Update tests - Move worker handler into a separate folder with separate package name Signed-off-by: Valery Piashchynski <[email protected]>
-rw-r--r--plugins/gzip/plugin.go6
-rw-r--r--plugins/headers/plugin.go6
-rw-r--r--plugins/http/plugin.go27
-rw-r--r--plugins/http/static/static.go (renamed from plugins/http/static.go)6
-rw-r--r--plugins/http/worker_handler/constants.go (renamed from plugins/http/constants.go)2
-rw-r--r--plugins/http/worker_handler/errors.go (renamed from plugins/http/errors.go)2
-rw-r--r--plugins/http/worker_handler/errors_windows.go (renamed from plugins/http/errors_windows.go)2
-rw-r--r--plugins/http/worker_handler/handler.go (renamed from plugins/http/handler.go)2
-rw-r--r--plugins/http/worker_handler/parse.go (renamed from plugins/http/parse.go)2
-rw-r--r--plugins/http/worker_handler/request.go (renamed from plugins/http/request.go)2
-rw-r--r--plugins/http/worker_handler/response.go (renamed from plugins/http/response.go)2
-rw-r--r--plugins/http/worker_handler/uploads.go (renamed from plugins/http/uploads.go)2
-rw-r--r--tests/plugins/http/configs/.rr-http-static.yaml4
-rw-r--r--tests/plugins/http/handler_test.go64
-rw-r--r--tests/plugins/http/http_plugin_test.go2
-rw-r--r--tests/plugins/http/parse_test.go6
-rw-r--r--tests/plugins/http/plugin_middleware.go12
-rw-r--r--tests/plugins/http/response_test.go18
-rw-r--r--tests/plugins/http/uploads_test.go10
-rw-r--r--tests/static/sample.txt2
20 files changed, 90 insertions, 89 deletions
diff --git a/plugins/gzip/plugin.go b/plugins/gzip/plugin.go
index 949c6888..18ee7b88 100644
--- a/plugins/gzip/plugin.go
+++ b/plugins/gzip/plugin.go
@@ -15,10 +15,10 @@ func (g *Plugin) Init() error {
return nil
}
-func (g *Plugin) Middleware(next http.Handler) http.HandlerFunc {
- return func(w http.ResponseWriter, r *http.Request) {
+func (g *Plugin) Middleware(next http.Handler) http.Handler {
+ return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
gziphandler.GzipHandler(next).ServeHTTP(w, r)
- }
+ })
}
func (g *Plugin) Name() string {
diff --git a/plugins/headers/plugin.go b/plugins/headers/plugin.go
index a5ee702f..dea0d127 100644
--- a/plugins/headers/plugin.go
+++ b/plugins/headers/plugin.go
@@ -38,9 +38,9 @@ func (s *Plugin) Init(cfg config.Configurer) error {
}
// middleware must return true if request/response pair is handled within the middleware.
-func (s *Plugin) Middleware(next http.Handler) http.HandlerFunc {
+func (s *Plugin) Middleware(next http.Handler) http.Handler {
// Define the http.HandlerFunc
- return func(w http.ResponseWriter, r *http.Request) {
+ return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if s.cfg.Headers.Request != nil {
for k, v := range s.cfg.Headers.Request {
r.Header.Add(k, v)
@@ -62,7 +62,7 @@ func (s *Plugin) Middleware(next http.Handler) http.HandlerFunc {
}
next.ServeHTTP(w, r)
- }
+ })
}
func (s *Plugin) Name() string {
diff --git a/plugins/http/plugin.go b/plugins/http/plugin.go
index dcfb7ddb..33efaf37 100644
--- a/plugins/http/plugin.go
+++ b/plugins/http/plugin.go
@@ -22,6 +22,8 @@ import (
"github.com/spiral/roadrunner/v2/plugins/config"
"github.com/spiral/roadrunner/v2/plugins/http/attributes"
httpConfig "github.com/spiral/roadrunner/v2/plugins/http/config"
+ "github.com/spiral/roadrunner/v2/plugins/http/static"
+ handler "github.com/spiral/roadrunner/v2/plugins/http/worker_handler"
"github.com/spiral/roadrunner/v2/plugins/logger"
"github.com/spiral/roadrunner/v2/plugins/server"
"github.com/spiral/roadrunner/v2/plugins/status"
@@ -35,16 +37,15 @@ const (
// PluginName declares plugin name.
PluginName = "http"
- // RR_HTTP env variable key (internal) if the HTTP presents
- RR_MODE = "RR_MODE" //nolint:golint,stylecheck
+ // RrMode RR_HTTP env variable key (internal) if the HTTP presents
+ RrMode = "RR_MODE"
- // HTTPS_SCHEME
- HTTPS_SCHEME = "https" //nolint:golint,stylecheck
+ HTTPSScheme = "https"
)
// Middleware interface
type Middleware interface {
- Middleware(f http.Handler) http.HandlerFunc
+ Middleware(f http.Handler) http.Handler
}
type middleware map[string]Middleware
@@ -69,7 +70,7 @@ type Plugin struct {
pool pool.Pool
// servers RR handler
- handler *Handler
+ handler *handler.Handler
// servers
http *http.Server
@@ -111,14 +112,14 @@ func (s *Plugin) Init(cfg config.Configurer, rrLogger logger.Logger, server serv
s.cfg.Env = make(map[string]string)
}
- s.cfg.Env[RR_MODE] = "http"
+ s.cfg.Env[RrMode] = "http"
s.server = server
return nil
}
func (s *Plugin) logCallback(event interface{}) {
- if ev, ok := event.(ResponseEvent); ok {
+ if ev, ok := event.(handler.ResponseEvent); ok {
s.log.Debug(fmt.Sprintf("%d %s %s", ev.Response.Status, ev.Request.Method, ev.Request.URI),
"remote", ev.Request.RemoteAddr,
"elapsed", ev.Elapsed().String(),
@@ -156,7 +157,7 @@ func (s *Plugin) serve(errCh chan error) { //nolint:gocognit
return
}
- s.handler, err = NewHandler(
+ s.handler, err = handler.NewHandler(
s.cfg.MaxRequestSize,
*s.cfg.Uploads,
s.cfg.Cidrs,
@@ -174,7 +175,7 @@ func (s *Plugin) serve(errCh chan error) { //nolint:gocognit
// if we have static, handler here, create a fileserver
if s.cfg.Static != nil {
- h := http.FileServer(StaticFilesHandler(s.cfg.Static))
+ h := http.FileServer(static.FS(s.cfg.Static))
// Static files handler
mux.HandleFunc(s.cfg.Static.Pattern, func(w http.ResponseWriter, r *http.Request) {
if s.cfg.Static.Request != nil {
@@ -429,7 +430,7 @@ func (s *Plugin) Reset() error {
s.log.Info("HTTP workers Pool successfully restarted")
- s.handler, err = NewHandler(
+ s.handler, err = handler.NewHandler(
s.cfg.MaxRequestSize,
*s.cfg.Uploads,
s.cfg.Cidrs,
@@ -500,7 +501,7 @@ func (s *Plugin) Ready() status.Status {
func (s *Plugin) redirect(w http.ResponseWriter, r *http.Request) {
target := &url.URL{
- Scheme: HTTPS_SCHEME,
+ Scheme: HTTPSScheme,
// host or host:port
Host: s.tlsAddr(r.Host, false),
Path: r.URL.Path,
@@ -641,7 +642,7 @@ func (s *Plugin) tlsAddr(host string, forcePort bool) string {
}
func applyMiddlewares(server *http.Server, middlewares map[string]Middleware, order []string, log logger.Logger) {
- for i := 0; i < len(order); i++ {
+ for i := len(order) - 1; i >= 0; i-- {
if mdwr, ok := middlewares[order[i]]; ok {
server.Handler = mdwr.Middleware(server.Handler)
} else {
diff --git a/plugins/http/static.go b/plugins/http/static/static.go
index be977fb3..d0278466 100644
--- a/plugins/http/static.go
+++ b/plugins/http/static/static.go
@@ -1,4 +1,4 @@
-package http
+package static
import (
"io/fs"
@@ -82,7 +82,7 @@ func (f FileSystem) Open(name string) (http.File, error) {
return nil, fs.ErrNotExist
}
-// StaticFilesHandler is a constructor for the http.FileSystem
-func StaticFilesHandler(config *httpConfig.Static) http.FileSystem {
+// FS is a constructor for the http.FileSystem
+func FS(config *httpConfig.Static) http.FileSystem {
return FileSystem{NewExtensionFilter(config.Allow, config.Forbid), http.Dir(config.Dir)}
}
diff --git a/plugins/http/constants.go b/plugins/http/worker_handler/constants.go
index c3d5c589..3355d9c2 100644
--- a/plugins/http/constants.go
+++ b/plugins/http/worker_handler/constants.go
@@ -1,4 +1,4 @@
-package http
+package handler
import "net/http"
diff --git a/plugins/http/errors.go b/plugins/http/worker_handler/errors.go
index 5889aa76..5fa8e64e 100644
--- a/plugins/http/errors.go
+++ b/plugins/http/worker_handler/errors.go
@@ -1,6 +1,6 @@
// +build !windows
-package http
+package handler
import (
"errors"
diff --git a/plugins/http/errors_windows.go b/plugins/http/worker_handler/errors_windows.go
index 3d0ba04c..390cc7d1 100644
--- a/plugins/http/errors_windows.go
+++ b/plugins/http/worker_handler/errors_windows.go
@@ -1,6 +1,6 @@
// +build windows
-package http
+package handler
import (
"errors"
diff --git a/plugins/http/handler.go b/plugins/http/worker_handler/handler.go
index d3c928aa..be53fc12 100644
--- a/plugins/http/handler.go
+++ b/plugins/http/worker_handler/handler.go
@@ -1,4 +1,4 @@
-package http
+package handler
import (
"net"
diff --git a/plugins/http/parse.go b/plugins/http/worker_handler/parse.go
index 780e1279..2790da2a 100644
--- a/plugins/http/parse.go
+++ b/plugins/http/worker_handler/parse.go
@@ -1,4 +1,4 @@
-package http
+package handler
import (
"net/http"
diff --git a/plugins/http/request.go b/plugins/http/worker_handler/request.go
index a1398819..178bc827 100644
--- a/plugins/http/request.go
+++ b/plugins/http/worker_handler/request.go
@@ -1,4 +1,4 @@
-package http
+package handler
import (
"fmt"
diff --git a/plugins/http/response.go b/plugins/http/worker_handler/response.go
index 17049ce1..1763d304 100644
--- a/plugins/http/response.go
+++ b/plugins/http/worker_handler/response.go
@@ -1,4 +1,4 @@
-package http
+package handler
import (
"io"
diff --git a/plugins/http/uploads.go b/plugins/http/worker_handler/uploads.go
index f9f8e1c8..e695000e 100644
--- a/plugins/http/uploads.go
+++ b/plugins/http/worker_handler/uploads.go
@@ -1,4 +1,4 @@
-package http
+package handler
import (
"github.com/spiral/roadrunner/v2/plugins/http/config"
diff --git a/tests/plugins/http/configs/.rr-http-static.yaml b/tests/plugins/http/configs/.rr-http-static.yaml
index 9bb2abc0..9351f020 100644
--- a/tests/plugins/http/configs/.rr-http-static.yaml
+++ b/tests/plugins/http/configs/.rr-http-static.yaml
@@ -1,5 +1,5 @@
server:
- command: "php ../../http/client.php pid pipes"
+ command: "php ../../psr-worker-bench.php"
user: ""
group: ""
env:
@@ -24,7 +24,7 @@ http:
response:
"output": "output-header"
pool:
- num_workers: 2
+ num_workers: 12
max_jobs: 0
allocate_timeout: 60s
destroy_timeout: 60s
diff --git a/tests/plugins/http/handler_test.go b/tests/plugins/http/handler_test.go
index cf445aad..575fe656 100644
--- a/tests/plugins/http/handler_test.go
+++ b/tests/plugins/http/handler_test.go
@@ -12,8 +12,8 @@ import (
"github.com/spiral/roadrunner/v2/pkg/pool"
"github.com/spiral/roadrunner/v2/pkg/transport/pipe"
- httpPlugin "github.com/spiral/roadrunner/v2/plugins/http"
"github.com/spiral/roadrunner/v2/plugins/http/config"
+ handler "github.com/spiral/roadrunner/v2/plugins/http/worker_handler"
"github.com/stretchr/testify/assert"
"net/http"
@@ -35,7 +35,7 @@ func TestHandler_Echo(t *testing.T) {
t.Fatal(err)
}
- h, err := httpPlugin.NewHandler(1024, config.Uploads{
+ h, err := handler.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, p)
@@ -66,7 +66,7 @@ func TestHandler_Echo(t *testing.T) {
}
func Test_HandlerErrors(t *testing.T) {
- _, err := httpPlugin.NewHandler(1024, config.Uploads{
+ _, err := handler.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, nil)
@@ -89,7 +89,7 @@ func TestHandler_Headers(t *testing.T) {
p.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, config.Uploads{
+ h, err := handler.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, p)
@@ -150,7 +150,7 @@ func TestHandler_Empty_User_Agent(t *testing.T) {
p.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, config.Uploads{
+ h, err := handler.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, p)
@@ -210,7 +210,7 @@ func TestHandler_User_Agent(t *testing.T) {
p.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, config.Uploads{
+ h, err := handler.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, p)
@@ -270,7 +270,7 @@ func TestHandler_Cookies(t *testing.T) {
p.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, config.Uploads{
+ h, err := handler.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, p)
@@ -335,7 +335,7 @@ func TestHandler_JsonPayload_POST(t *testing.T) {
p.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, config.Uploads{
+ h, err := handler.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, p)
@@ -399,7 +399,7 @@ func TestHandler_JsonPayload_PUT(t *testing.T) {
p.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, config.Uploads{
+ h, err := handler.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, p)
@@ -459,7 +459,7 @@ func TestHandler_JsonPayload_PATCH(t *testing.T) {
p.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, config.Uploads{
+ h, err := handler.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, p)
@@ -519,7 +519,7 @@ func TestHandler_FormData_POST(t *testing.T) {
p.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, config.Uploads{
+ h, err := handler.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, p)
@@ -592,7 +592,7 @@ func TestHandler_FormData_POST_Overwrite(t *testing.T) {
p.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, config.Uploads{
+ h, err := handler.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, p)
@@ -665,7 +665,7 @@ func TestHandler_FormData_POST_Form_UrlEncoded_Charset(t *testing.T) {
p.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, config.Uploads{
+ h, err := handler.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, p)
@@ -737,7 +737,7 @@ func TestHandler_FormData_PUT(t *testing.T) {
p.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, config.Uploads{
+ h, err := handler.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, p)
@@ -809,7 +809,7 @@ func TestHandler_FormData_PATCH(t *testing.T) {
p.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, config.Uploads{
+ h, err := handler.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, p)
@@ -881,7 +881,7 @@ func TestHandler_Multipart_POST(t *testing.T) {
p.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, config.Uploads{
+ h, err := handler.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, p)
@@ -995,7 +995,7 @@ func TestHandler_Multipart_PUT(t *testing.T) {
p.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, config.Uploads{
+ h, err := handler.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, p)
@@ -1109,7 +1109,7 @@ func TestHandler_Multipart_PATCH(t *testing.T) {
p.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, config.Uploads{
+ h, err := handler.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, p)
@@ -1225,7 +1225,7 @@ func TestHandler_Error(t *testing.T) {
p.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, config.Uploads{
+ h, err := handler.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, p)
@@ -1271,7 +1271,7 @@ func TestHandler_Error2(t *testing.T) {
p.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, config.Uploads{
+ h, err := handler.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, p)
@@ -1317,7 +1317,7 @@ func TestHandler_Error3(t *testing.T) {
p.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1, config.Uploads{
+ h, err := handler.NewHandler(1, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, p)
@@ -1376,7 +1376,7 @@ func TestHandler_ResponseDuration(t *testing.T) {
p.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, config.Uploads{
+ h, err := handler.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, p)
@@ -1401,7 +1401,7 @@ func TestHandler_ResponseDuration(t *testing.T) {
gotresp := make(chan interface{})
h.AddListener(func(event interface{}) {
switch t := event.(type) {
- case httpPlugin.ResponseEvent:
+ case handler.ResponseEvent:
if t.Elapsed() > 0 {
close(gotresp)
}
@@ -1437,7 +1437,7 @@ func TestHandler_ResponseDurationDelayed(t *testing.T) {
p.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, config.Uploads{
+ h, err := handler.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, p)
@@ -1462,7 +1462,7 @@ func TestHandler_ResponseDurationDelayed(t *testing.T) {
gotresp := make(chan interface{})
h.AddListener(func(event interface{}) {
switch tp := event.(type) {
- case httpPlugin.ResponseEvent:
+ case handler.ResponseEvent:
if tp.Elapsed() > time.Second {
close(gotresp)
}
@@ -1497,7 +1497,7 @@ func TestHandler_ErrorDuration(t *testing.T) {
p.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, config.Uploads{
+ h, err := handler.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, p)
@@ -1522,7 +1522,7 @@ func TestHandler_ErrorDuration(t *testing.T) {
goterr := make(chan interface{})
h.AddListener(func(event interface{}) {
switch tp := event.(type) {
- case httpPlugin.ErrorEvent:
+ case handler.ErrorEvent:
if tp.Elapsed() > 0 {
close(goterr)
}
@@ -1571,7 +1571,7 @@ func TestHandler_IP(t *testing.T) {
p.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, config.Uploads{
+ h, err := handler.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, cidrs, p)
@@ -1632,7 +1632,7 @@ func TestHandler_XRealIP(t *testing.T) {
p.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, config.Uploads{
+ h, err := handler.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, cidrs, p)
@@ -1698,7 +1698,7 @@ func TestHandler_XForwardedFor(t *testing.T) {
p.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, config.Uploads{
+ h, err := handler.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, cidrs, p)
@@ -1763,7 +1763,7 @@ func TestHandler_XForwardedFor_NotTrustedRemoteIp(t *testing.T) {
p.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, config.Uploads{
+ h, err := handler.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, cidrs, p)
@@ -1811,7 +1811,7 @@ func BenchmarkHandler_Listen_Echo(b *testing.B) {
p.Destroy(context.Background())
}()
- h, err := httpPlugin.NewHandler(1024, config.Uploads{
+ h, err := handler.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, p)
diff --git a/tests/plugins/http/http_plugin_test.go b/tests/plugins/http/http_plugin_test.go
index 000fd25d..61486eef 100644
--- a/tests/plugins/http/http_plugin_test.go
+++ b/tests/plugins/http/http_plugin_test.go
@@ -1671,7 +1671,7 @@ func staticNotForbid(t *testing.T) {
func serveStaticSample(t *testing.T) {
b, r, err := get("http://localhost:21603/tests/static/sample.txt")
assert.NoError(t, err)
- assert.Equal(t, "sample", b)
+ assert.Equal(t, "sample\n", b)
_ = r.Body.Close()
}
diff --git a/tests/plugins/http/parse_test.go b/tests/plugins/http/parse_test.go
index 5cc1ce32..15c82839 100644
--- a/tests/plugins/http/parse_test.go
+++ b/tests/plugins/http/parse_test.go
@@ -3,7 +3,7 @@ package http
import (
"testing"
- "github.com/spiral/roadrunner/v2/plugins/http"
+ handler "github.com/spiral/roadrunner/v2/plugins/http/worker_handler"
)
var samples = []struct {
@@ -21,7 +21,7 @@ var samples = []struct {
func Test_FetchIndexes(t *testing.T) {
for i := 0; i < len(samples); i++ {
- r := http.FetchIndexes(samples[i].in)
+ r := handler.FetchIndexes(samples[i].in)
if !same(r, samples[i].out) {
t.Errorf("got %q, want %q", r, samples[i].out)
}
@@ -31,7 +31,7 @@ func Test_FetchIndexes(t *testing.T) {
func BenchmarkConfig_FetchIndexes(b *testing.B) {
for _, tt := range samples {
for n := 0; n < b.N; n++ {
- r := http.FetchIndexes(tt.in)
+ r := handler.FetchIndexes(tt.in)
if !same(r, tt.out) {
b.Fail()
}
diff --git a/tests/plugins/http/plugin_middleware.go b/tests/plugins/http/plugin_middleware.go
index 00640b69..9f04d6db 100644
--- a/tests/plugins/http/plugin_middleware.go
+++ b/tests/plugins/http/plugin_middleware.go
@@ -18,8 +18,8 @@ func (p *PluginMiddleware) Init(cfg config.Configurer) error {
}
// Middleware test
-func (p *PluginMiddleware) Middleware(next http.Handler) http.HandlerFunc {
- return func(w http.ResponseWriter, r *http.Request) {
+func (p *PluginMiddleware) Middleware(next http.Handler) http.Handler {
+ return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/halt" {
w.WriteHeader(500)
_, err := w.Write([]byte("halted"))
@@ -29,7 +29,7 @@ func (p *PluginMiddleware) Middleware(next http.Handler) http.HandlerFunc {
} else {
next.ServeHTTP(w, r)
}
- }
+ })
}
// Name test
@@ -49,8 +49,8 @@ func (p *PluginMiddleware2) Init(cfg config.Configurer) error {
}
// Middleware test
-func (p *PluginMiddleware2) Middleware(next http.Handler) http.HandlerFunc {
- return func(w http.ResponseWriter, r *http.Request) {
+func (p *PluginMiddleware2) Middleware(next http.Handler) http.Handler {
+ return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/boom" {
w.WriteHeader(555)
_, err := w.Write([]byte("boom"))
@@ -60,7 +60,7 @@ func (p *PluginMiddleware2) Middleware(next http.Handler) http.HandlerFunc {
} else {
next.ServeHTTP(w, r)
}
- }
+ })
}
// Name test
diff --git a/tests/plugins/http/response_test.go b/tests/plugins/http/response_test.go
index dc9856ac..3564d9cd 100644
--- a/tests/plugins/http/response_test.go
+++ b/tests/plugins/http/response_test.go
@@ -7,7 +7,7 @@ import (
"testing"
"github.com/spiral/roadrunner/v2/pkg/payload"
- httpPlugin "github.com/spiral/roadrunner/v2/plugins/http"
+ handler "github.com/spiral/roadrunner/v2/plugins/http/worker_handler"
"github.com/stretchr/testify/assert"
)
@@ -45,13 +45,13 @@ func (tw *testWriter) Push(target string, opts *http.PushOptions) error {
}
func TestNewResponse_Error(t *testing.T) {
- r, err := httpPlugin.NewResponse(payload.Payload{Context: []byte(`invalid payload`)})
+ r, err := handler.NewResponse(payload.Payload{Context: []byte(`invalid payload`)})
assert.Error(t, err)
assert.Nil(t, r)
}
func TestNewResponse_Write(t *testing.T) {
- r, err := httpPlugin.NewResponse(payload.Payload{
+ r, err := handler.NewResponse(payload.Payload{
Context: []byte(`{"headers":{"key":["value"]},"status": 301}`),
Body: []byte(`sample body`),
})
@@ -68,7 +68,7 @@ func TestNewResponse_Write(t *testing.T) {
}
func TestNewResponse_Stream(t *testing.T) {
- r, err := httpPlugin.NewResponse(payload.Payload{
+ r, err := handler.NewResponse(payload.Payload{
Context: []byte(`{"headers":{"key":["value"]},"status": 301}`),
})
@@ -93,7 +93,7 @@ func TestNewResponse_Stream(t *testing.T) {
}
func TestNewResponse_StreamError(t *testing.T) {
- r, err := httpPlugin.NewResponse(payload.Payload{
+ r, err := handler.NewResponse(payload.Payload{
Context: []byte(`{"headers":{"key":["value"]},"status": 301}`),
})
@@ -114,7 +114,7 @@ func TestNewResponse_StreamError(t *testing.T) {
}
func TestWrite_HandlesPush(t *testing.T) {
- r, err := httpPlugin.NewResponse(payload.Payload{
+ r, err := handler.NewResponse(payload.Payload{
Context: []byte(`{"headers":{"Http2-Push":["/test.js"],"content-type":["text/html"]},"status": 200}`),
})
@@ -129,7 +129,7 @@ func TestWrite_HandlesPush(t *testing.T) {
}
func TestWrite_HandlesTrailers(t *testing.T) {
- r, err := httpPlugin.NewResponse(payload.Payload{
+ r, err := handler.NewResponse(payload.Payload{
Context: []byte(`{"headers":{"Trailer":["foo, bar", "baz"],"foo":["test"],"bar":["demo"]},"status": 200}`),
})
@@ -139,7 +139,7 @@ func TestWrite_HandlesTrailers(t *testing.T) {
w := &testWriter{h: http.Header(make(map[string][]string))}
assert.NoError(t, r.Write(w))
- assert.Nil(t, w.h[httpPlugin.TrailerHeaderKey])
+ assert.Nil(t, w.h[handler.TrailerHeaderKey])
assert.Nil(t, w.h["foo"]) //nolint:staticcheck
assert.Nil(t, w.h["baz"]) //nolint:staticcheck
@@ -148,7 +148,7 @@ func TestWrite_HandlesTrailers(t *testing.T) {
}
func TestWrite_HandlesHandlesWhitespacesInTrailer(t *testing.T) {
- r, err := httpPlugin.NewResponse(payload.Payload{
+ r, err := handler.NewResponse(payload.Payload{
Context: []byte(
`{"headers":{"Trailer":["foo\t,bar , baz"],"foo":["a"],"bar":["b"],"baz":["c"]},"status": 200}`),
})
diff --git a/tests/plugins/http/uploads_test.go b/tests/plugins/http/uploads_test.go
index bc7e17df..5c39589c 100644
--- a/tests/plugins/http/uploads_test.go
+++ b/tests/plugins/http/uploads_test.go
@@ -18,8 +18,8 @@ import (
j "github.com/json-iterator/go"
poolImpl "github.com/spiral/roadrunner/v2/pkg/pool"
"github.com/spiral/roadrunner/v2/pkg/transport/pipe"
- httpPlugin "github.com/spiral/roadrunner/v2/plugins/http"
"github.com/spiral/roadrunner/v2/plugins/http/config"
+ handler "github.com/spiral/roadrunner/v2/plugins/http/worker_handler"
"github.com/stretchr/testify/assert"
)
@@ -40,7 +40,7 @@ func TestHandler_Upload_File(t *testing.T) {
t.Fatal(err)
}
- h, err := httpPlugin.NewHandler(1024, config.Uploads{
+ h, err := handler.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, pool)
@@ -123,7 +123,7 @@ func TestHandler_Upload_NestedFile(t *testing.T) {
t.Fatal(err)
}
- h, err := httpPlugin.NewHandler(1024, config.Uploads{
+ h, err := handler.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
}, nil, pool)
@@ -206,7 +206,7 @@ func TestHandler_Upload_File_NoTmpDir(t *testing.T) {
t.Fatal(err)
}
- h, err := httpPlugin.NewHandler(1024, config.Uploads{
+ h, err := handler.NewHandler(1024, config.Uploads{
Dir: "-------",
Forbid: []string{},
}, nil, pool)
@@ -289,7 +289,7 @@ func TestHandler_Upload_File_Forbids(t *testing.T) {
t.Fatal(err)
}
- h, err := httpPlugin.NewHandler(1024, config.Uploads{
+ h, err := handler.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{".go"},
}, nil, pool)
diff --git a/tests/static/sample.txt b/tests/static/sample.txt
index eed7e79a..d64a3d96 100644
--- a/tests/static/sample.txt
+++ b/tests/static/sample.txt
@@ -1 +1 @@
-sample \ No newline at end of file
+sample