summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-01-13 07:07:16 +0000
committerGitHub <[email protected]>2021-01-13 07:07:16 +0000
commitf18e7f6920590ee6f2e59be508518b70a4611638 (patch)
tree2f80c427e740c2c6f7f2a47be2b869b6d9847e58 /service
parent5dc83ef5eee77f4d1ef557e5f8b566e75892680d (diff)
parentbbfcd4fb6eb138c616dab01ea610fbf6ed15985b (diff)
Merge #472
472: feat(http): Distinct app and internal error codes in the handleError function r=48d90782 a=48d90782 This PR introduces distinct error codes for the app and internal RR errors. Errors: ```go roadrunner.ErrNoAssociatedPool roadrunner.ErrAllocateWorker roadrunner.ErrWorkerNotReady roadrunner.ErrEmptyPayload roadrunner.ErrPoolStopped roadrunner.ErrWorkerAllocateTimeout roadrunner.ErrAllWorkersAreDead ``` now associated with the internal error codes. All other errors are application errors. Some types of errors are impossible to distinguish in the RR1, for example `json.Unmarshall` internal error or similar. The `.rr.yaml` now contain two more options for the errors. ```yaml http: internalErrorCode: 502, appErrorCode: 502 ``` Default behavior unchanged (500 error code as before), but now might be overridden. closes #471 Co-authored-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'service')
-rw-r--r--service/container.go5
-rw-r--r--service/container_test.go7
-rw-r--r--service/entry_test.go3
-rw-r--r--service/env/config_test.go5
-rw-r--r--service/env/service_test.go3
-rw-r--r--service/gzip/config_test.go5
-rw-r--r--service/gzip/service.go4
-rw-r--r--service/gzip/service_test.go3
-rw-r--r--service/headers/config_test.go5
-rw-r--r--service/headers/service.go3
-rw-r--r--service/headers/service_test.go9
-rw-r--r--service/health/config_test.go5
-rw-r--r--service/health/service.go7
-rw-r--r--service/health/service_test.go3
-rw-r--r--service/http/attributes/attributes_test.go3
-rw-r--r--service/http/config.go19
-rw-r--r--service/http/config_test.go13
-rw-r--r--service/http/fcgi_test.go9
-rw-r--r--service/http/handler.go32
-rw-r--r--service/http/handler_test.go46
-rw-r--r--service/http/request.go6
-rw-r--r--service/http/response.go7
-rw-r--r--service/http/rpc_test.go13
-rw-r--r--service/http/service.go7
-rw-r--r--service/http/service_test.go18
-rw-r--r--service/http/ssl_test.go10
-rw-r--r--service/http/uploads.go7
-rw-r--r--service/http/uploads_config_test.go3
-rw-r--r--service/http/uploads_test.go9
-rw-r--r--service/limit/config.go3
-rw-r--r--service/limit/config_test.go5
-rw-r--r--service/limit/controller.go3
-rw-r--r--service/limit/state_filter.go3
-rw-r--r--service/metrics/config_test.go2
-rw-r--r--service/metrics/rpc_test.go9
-rw-r--r--service/metrics/service_test.go9
-rw-r--r--service/reload/config.go3
-rw-r--r--service/reload/config_test.go3
-rw-r--r--service/rpc/config.go5
-rw-r--r--service/rpc/config_test.go3
-rw-r--r--service/rpc/service.go5
-rw-r--r--service/rpc/service_test.go5
-rw-r--r--service/static/config.go3
-rw-r--r--service/static/config_test.go3
-rw-r--r--service/static/service.go3
-rw-r--r--service/static/service_test.go15
46 files changed, 227 insertions, 124 deletions
diff --git a/service/container.go b/service/container.go
index 77a6dfc0..49eea733 100644
--- a/service/container.go
+++ b/service/container.go
@@ -2,10 +2,11 @@ package service
import (
"fmt"
- "github.com/pkg/errors"
- "github.com/sirupsen/logrus"
"reflect"
"sync"
+
+ "github.com/pkg/errors"
+ "github.com/sirupsen/logrus"
)
var errNoConfig = fmt.Errorf("no config has been provided")
diff --git a/service/container_test.go b/service/container_test.go
index b3ec7054..f990b2cb 100644
--- a/service/container_test.go
+++ b/service/container_test.go
@@ -2,13 +2,14 @@ package service
import (
"errors"
+ "sync"
+ "testing"
+ "time"
+
json "github.com/json-iterator/go"
"github.com/sirupsen/logrus"
"github.com/sirupsen/logrus/hooks/test"
"github.com/stretchr/testify/assert"
- "sync"
- "testing"
- "time"
)
type testService struct {
diff --git a/service/entry_test.go b/service/entry_test.go
index b5c71a10..5ca9c338 100644
--- a/service/entry_test.go
+++ b/service/entry_test.go
@@ -1,8 +1,9 @@
package service
import (
- "github.com/stretchr/testify/assert"
"testing"
+
+ "github.com/stretchr/testify/assert"
)
func TestEntry_CanServeFalse(t *testing.T) {
diff --git a/service/env/config_test.go b/service/env/config_test.go
index a526990d..cc2bdf97 100644
--- a/service/env/config_test.go
+++ b/service/env/config_test.go
@@ -1,15 +1,16 @@
package env
import (
+ "testing"
+
json "github.com/json-iterator/go"
"github.com/spiral/roadrunner/service"
"github.com/stretchr/testify/assert"
- "testing"
)
type mockCfg struct{ cfg string }
-func (cfg *mockCfg) Get(name string) service.Config { return nil }
+func (cfg *mockCfg) Get(name string) service.Config { return nil }
func (cfg *mockCfg) Unmarshal(out interface{}) error {
j := json.ConfigCompatibleWithStandardLibrary
return j.Unmarshal([]byte(cfg.cfg), out)
diff --git a/service/env/service_test.go b/service/env/service_test.go
index 19cc03c7..a354214c 100644
--- a/service/env/service_test.go
+++ b/service/env/service_test.go
@@ -1,8 +1,9 @@
package env
import (
- "github.com/stretchr/testify/assert"
"testing"
+
+ "github.com/stretchr/testify/assert"
)
func Test_NewService(t *testing.T) {
diff --git a/service/gzip/config_test.go b/service/gzip/config_test.go
index c2168166..8d03aecf 100644
--- a/service/gzip/config_test.go
+++ b/service/gzip/config_test.go
@@ -1,15 +1,16 @@
package gzip
import (
+ "testing"
+
json "github.com/json-iterator/go"
"github.com/spiral/roadrunner/service"
"github.com/stretchr/testify/assert"
- "testing"
)
type mockCfg struct{ cfg string }
-func (cfg *mockCfg) Get(name string) service.Config { return nil }
+func (cfg *mockCfg) Get(name string) service.Config { return nil }
func (cfg *mockCfg) Unmarshal(out interface{}) error {
j := json.ConfigCompatibleWithStandardLibrary
return j.Unmarshal([]byte(cfg.cfg), out)
diff --git a/service/gzip/service.go b/service/gzip/service.go
index 231ba4d9..2ba95158 100644
--- a/service/gzip/service.go
+++ b/service/gzip/service.go
@@ -2,13 +2,15 @@ package gzip
import (
"errors"
+ "net/http"
+
"github.com/NYTimes/gziphandler"
rrhttp "github.com/spiral/roadrunner/service/http"
- "net/http"
)
// ID contains default service name.
const ID = "gzip"
+
var httpNotInitialized = errors.New("http service should be defined properly in config to use gzip")
type Service struct {
diff --git a/service/gzip/service_test.go b/service/gzip/service_test.go
index 778bdacd..d886a339 100644
--- a/service/gzip/service_test.go
+++ b/service/gzip/service_test.go
@@ -1,13 +1,14 @@
package gzip
import (
+ "testing"
+
json "github.com/json-iterator/go"
"github.com/sirupsen/logrus"
"github.com/sirupsen/logrus/hooks/test"
"github.com/spiral/roadrunner/service"
rrhttp "github.com/spiral/roadrunner/service/http"
"github.com/stretchr/testify/assert"
- "testing"
)
type testCfg struct {
diff --git a/service/headers/config_test.go b/service/headers/config_test.go
index 6ea02f67..4b7c56df 100644
--- a/service/headers/config_test.go
+++ b/service/headers/config_test.go
@@ -1,15 +1,16 @@
package headers
import (
+ "testing"
+
json "github.com/json-iterator/go"
"github.com/spiral/roadrunner/service"
"github.com/stretchr/testify/assert"
- "testing"
)
type mockCfg struct{ cfg string }
-func (cfg *mockCfg) Get(name string) service.Config { return nil }
+func (cfg *mockCfg) Get(name string) service.Config { return nil }
func (cfg *mockCfg) Unmarshal(out interface{}) error {
j := json.ConfigCompatibleWithStandardLibrary
return j.Unmarshal([]byte(cfg.cfg), out)
diff --git a/service/headers/service.go b/service/headers/service.go
index 429219d7..a3a9d9da 100644
--- a/service/headers/service.go
+++ b/service/headers/service.go
@@ -1,9 +1,10 @@
package headers
import (
- rrhttp "github.com/spiral/roadrunner/service/http"
"net/http"
"strconv"
+
+ rrhttp "github.com/spiral/roadrunner/service/http"
)
// ID contains default service name.
diff --git a/service/headers/service_test.go b/service/headers/service_test.go
index a67def02..03a55d1e 100644
--- a/service/headers/service_test.go
+++ b/service/headers/service_test.go
@@ -1,6 +1,11 @@
package headers
import (
+ "io/ioutil"
+ "net/http"
+ "testing"
+ "time"
+
"github.com/cenkalti/backoff/v4"
json "github.com/json-iterator/go"
"github.com/sirupsen/logrus"
@@ -8,10 +13,6 @@ import (
"github.com/spiral/roadrunner/service"
rrhttp "github.com/spiral/roadrunner/service/http"
"github.com/stretchr/testify/assert"
- "io/ioutil"
- "net/http"
- "testing"
- "time"
)
type testCfg struct {
diff --git a/service/health/config_test.go b/service/health/config_test.go
index ba7d7c12..c02c46fc 100644
--- a/service/health/config_test.go
+++ b/service/health/config_test.go
@@ -1,16 +1,17 @@
package health
import (
- json "github.com/json-iterator/go"
"testing"
+ json "github.com/json-iterator/go"
+
"github.com/spiral/roadrunner/service"
"github.com/stretchr/testify/assert"
)
type mockCfg struct{ cfg string }
-func (cfg *mockCfg) Get(name string) service.Config { return nil }
+func (cfg *mockCfg) Get(name string) service.Config { return nil }
func (cfg *mockCfg) Unmarshal(out interface{}) error {
j := json.ConfigCompatibleWithStandardLibrary
return j.Unmarshal([]byte(cfg.cfg), out)
diff --git a/service/health/service.go b/service/health/service.go
index ce127340..b9b22a8a 100644
--- a/service/health/service.go
+++ b/service/health/service.go
@@ -3,11 +3,12 @@ package health
import (
"context"
"fmt"
- "github.com/sirupsen/logrus"
"net/http"
"sync"
"time"
+ "github.com/sirupsen/logrus"
+
rrhttp "github.com/spiral/roadrunner/service/http"
)
@@ -45,8 +46,8 @@ func (s *Service) Serve() error {
// Configure and start the http server
s.mu.Lock()
s.http = &http.Server{
- Addr: s.cfg.Address,
- Handler: s,
+ Addr: s.cfg.Address,
+ Handler: s,
IdleTimeout: time.Hour * 24,
ReadTimeout: time.Minute * 60,
MaxHeaderBytes: maxHeaderSize,
diff --git a/service/health/service_test.go b/service/health/service_test.go
index fc743a62..3488d631 100644
--- a/service/health/service_test.go
+++ b/service/health/service_test.go
@@ -1,12 +1,13 @@
package health
import (
- json "github.com/json-iterator/go"
"io/ioutil"
"net/http"
"testing"
"time"
+ json "github.com/json-iterator/go"
+
"github.com/sirupsen/logrus"
"github.com/sirupsen/logrus/hooks/test"
"github.com/spiral/roadrunner/service"
diff --git a/service/http/attributes/attributes_test.go b/service/http/attributes/attributes_test.go
index 2360fd12..d914f6fa 100644
--- a/service/http/attributes/attributes_test.go
+++ b/service/http/attributes/attributes_test.go
@@ -1,9 +1,10 @@
package attributes
import (
- "github.com/stretchr/testify/assert"
"net/http"
"testing"
+
+ "github.com/stretchr/testify/assert"
)
func TestAllAttributes(t *testing.T) {
diff --git a/service/http/config.go b/service/http/config.go
index 00f61652..34733e44 100644
--- a/service/http/config.go
+++ b/service/http/config.go
@@ -3,15 +3,21 @@ package http
import (
"errors"
"fmt"
- "github.com/spiral/roadrunner"
- "github.com/spiral/roadrunner/service"
"net"
+ "net/http"
"os"
"strings"
+
+ "github.com/spiral/roadrunner"
+ "github.com/spiral/roadrunner/service"
)
// Config configures RoadRunner HTTP server.
type Config struct {
+ // AppErrorCode is error code for the application errors (default 500)
+ AppErrorCode uint64
+ // Error code for the RR pool or worker errors
+ InternalErrorCode uint64
// Port and port to handle as http server.
Address string
@@ -60,7 +66,6 @@ type HTTP2Config struct {
func (cfg *HTTP2Config) InitDefaults() error {
cfg.Enabled = true
cfg.MaxConcurrentStreams = 128
-
return nil
}
@@ -109,6 +114,14 @@ func (c *Config) EnableFCGI() bool {
// Hydrate must populate Config values using given Config source. Must return error if Config is not valid.
func (c *Config) Hydrate(cfg service.Config) error {
+ if c.AppErrorCode == 0 {
+ // set default behaviour - 500 error code
+ c.AppErrorCode = http.StatusInternalServerError
+ }
+ if c.InternalErrorCode == 0 {
+ // set default behaviour - 500 error code
+ c.InternalErrorCode = http.StatusInternalServerError
+ }
if c.Workers == nil {
c.Workers = &roadrunner.ServerConfig{}
}
diff --git a/service/http/config_test.go b/service/http/config_test.go
index d95e0995..18b8f5a3 100644
--- a/service/http/config_test.go
+++ b/service/http/config_test.go
@@ -1,21 +1,20 @@
package http
import (
- json "github.com/json-iterator/go"
- "github.com/spiral/roadrunner"
- "github.com/spiral/roadrunner/service"
- "github.com/stretchr/testify/assert"
"os"
"testing"
"time"
+
+ "github.com/spiral/roadrunner"
+ "github.com/spiral/roadrunner/service"
+ "github.com/stretchr/testify/assert"
)
type mockCfg struct{ cfg string }
-func (cfg *mockCfg) Get(name string) service.Config { return nil }
+func (cfg *mockCfg) Get(name string) service.Config { return nil }
func (cfg *mockCfg) Unmarshal(out interface{}) error {
- j := json.ConfigCompatibleWithStandardLibrary
- return j.Unmarshal([]byte(cfg.cfg), out)
+ return json.Unmarshal([]byte(cfg.cfg), out)
}
func Test_Config_Hydrate_Error1(t *testing.T) {
diff --git a/service/http/fcgi_test.go b/service/http/fcgi_test.go
index e68b2e7f..cf67a68b 100644
--- a/service/http/fcgi_test.go
+++ b/service/http/fcgi_test.go
@@ -1,15 +1,16 @@
package http
import (
+ "io/ioutil"
+ "net/http/httptest"
+ "testing"
+ "time"
+
"github.com/sirupsen/logrus"
"github.com/sirupsen/logrus/hooks/test"
"github.com/spiral/roadrunner/service"
"github.com/stretchr/testify/assert"
"github.com/yookoala/gofast"
- "io/ioutil"
- "net/http/httptest"
- "testing"
- "time"
)
func Test_FCGI_Service_Echo(t *testing.T) {
diff --git a/service/http/handler.go b/service/http/handler.go
index eca05483..43f894d7 100644
--- a/service/http/handler.go
+++ b/service/http/handler.go
@@ -61,11 +61,13 @@ func (e *ResponseEvent) Elapsed() time.Duration {
// Handler serves http connections to underlying PHP application using PSR-7 protocol. Context will include request headers,
// parsed files and query, payload will include parsed form dataTree (if any).
type Handler struct {
- cfg *Config
- log *logrus.Logger
- rr *roadrunner.Server
- mul sync.Mutex
- lsn func(event int, ctx interface{})
+ cfg *Config
+ log *logrus.Logger
+ rr *roadrunner.Server
+ mul sync.Mutex
+ lsn func(event int, ctx interface{})
+ internalErrorCode uint64
+ appErrorCode uint64
}
// Listen attaches handler event controller.
@@ -131,6 +133,10 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
// handleError sends error.
+/*
+handleError distinct RR errors and App errors
+You can set return distinct error codes for the App and for the RR
+*/
func (h *Handler) handleError(w http.ResponseWriter, r *http.Request, err error, start time.Time) {
// if pipe is broken, there is no sense to write the header
// in this case we just report about error
@@ -138,8 +144,20 @@ func (h *Handler) handleError(w http.ResponseWriter, r *http.Request, err error,
h.throw(EventError, &ErrorEvent{Request: r, Error: err, start: start, elapsed: time.Since(start)})
return
}
- // ResponseWriter is ok, write the error code
- w.WriteHeader(500)
+ if errors.Is(err, roadrunner.ErrNoAssociatedPool) ||
+ errors.Is(err, roadrunner.ErrAllocateWorker) ||
+ errors.Is(err, roadrunner.ErrWorkerNotReady) ||
+ errors.Is(err, roadrunner.ErrEmptyPayload) ||
+ errors.Is(err, roadrunner.ErrPoolStopped) ||
+ errors.Is(err, roadrunner.ErrWorkerAllocateTimeout) ||
+ errors.Is(err, roadrunner.ErrAllWorkersAreDead) {
+ // for the RR errors, write custom error code
+ w.WriteHeader(int(h.internalErrorCode))
+ } else {
+ // ResponseWriter is ok, write the error code
+ w.WriteHeader(int(h.appErrorCode))
+ }
+
_, err2 := w.Write([]byte(err.Error()))
// error during the writing to the ResponseWriter
if err2 != nil {
diff --git a/service/http/handler_test.go b/service/http/handler_test.go
index 951bcbfd..7a50bf97 100644
--- a/service/http/handler_test.go
+++ b/service/http/handler_test.go
@@ -3,8 +3,6 @@ package http
import (
"bytes"
"context"
- "github.com/spiral/roadrunner"
- "github.com/stretchr/testify/assert"
"io/ioutil"
"mime/multipart"
"net/http"
@@ -15,6 +13,9 @@ import (
"strings"
"testing"
"time"
+
+ "github.com/spiral/roadrunner"
+ "github.com/stretchr/testify/assert"
)
// get request and return body
@@ -110,6 +111,7 @@ func TestHandler_Echo(t *testing.T) {
func Test_HandlerErrors(t *testing.T) {
h := &Handler{
+ internalErrorCode: 500,
cfg: &Config{
MaxRequestSize: 1024,
Uploads: &UploadsConfig{
@@ -135,8 +137,38 @@ func Test_HandlerErrors(t *testing.T) {
assert.Equal(t, 500, wr.Code)
}
+func Test_HandlerErrorsPoolErrorCode(t *testing.T) {
+ h := &Handler{
+ internalErrorCode: 777,
+ cfg: &Config{
+ MaxRequestSize: 1024,
+ Uploads: &UploadsConfig{
+ Dir: os.TempDir(),
+ Forbid: []string{},
+ },
+ },
+ rr: roadrunner.NewServer(&roadrunner.ServerConfig{
+ Command: "php ../../tests/http/client.php echo pipes",
+ Relay: "pipes",
+ Pool: &roadrunner.Config{
+ NumWorkers: 1,
+ AllocateTimeout: 10000000,
+ DestroyTimeout: 10000000,
+ },
+ }),
+ }
+
+ wr := httptest.NewRecorder()
+ rq := httptest.NewRequest("POST", "/", bytes.NewBuffer([]byte("data")))
+
+ h.ServeHTTP(wr, rq)
+ assert.Equal(t, 777, wr.Code)
+}
+
func Test_Handler_JSON_error(t *testing.T) {
h := &Handler{
+ appErrorCode: 500,
+ internalErrorCode: 500,
cfg: &Config{
MaxRequestSize: 1024,
Uploads: &UploadsConfig{
@@ -1329,6 +1361,8 @@ func TestHandler_Multipart_PATCH(t *testing.T) {
func TestHandler_Error(t *testing.T) {
h := &Handler{
+ appErrorCode: http.StatusInternalServerError,
+ internalErrorCode: http.StatusInternalServerError,
cfg: &Config{
MaxRequestSize: 1024,
Uploads: &UploadsConfig{
@@ -1373,6 +1407,8 @@ func TestHandler_Error(t *testing.T) {
func TestHandler_Error2(t *testing.T) {
h := &Handler{
+ appErrorCode: http.StatusInternalServerError,
+ internalErrorCode: http.StatusInternalServerError,
cfg: &Config{
MaxRequestSize: 1024,
Uploads: &UploadsConfig{
@@ -1417,6 +1453,8 @@ func TestHandler_Error2(t *testing.T) {
func TestHandler_Error3(t *testing.T) {
h := &Handler{
+ appErrorCode: http.StatusInternalServerError,
+ internalErrorCode: http.StatusInternalServerError,
cfg: &Config{
MaxRequestSize: 1,
Uploads: &UploadsConfig{
@@ -1478,6 +1516,8 @@ func TestHandler_Error3(t *testing.T) {
func TestHandler_ResponseDuration(t *testing.T) {
h := &Handler{
+ appErrorCode: http.StatusInternalServerError,
+ internalErrorCode: http.StatusInternalServerError,
cfg: &Config{
MaxRequestSize: 1024,
Uploads: &UploadsConfig{
@@ -1596,6 +1636,7 @@ func TestHandler_ResponseDurationDelayed(t *testing.T) {
func TestHandler_ErrorDuration(t *testing.T) {
h := &Handler{
+ appErrorCode: http.StatusInternalServerError,
cfg: &Config{
MaxRequestSize: 1024,
Uploads: &UploadsConfig{
@@ -1654,6 +1695,7 @@ func TestHandler_ErrorDuration(t *testing.T) {
func TestHandler_IP(t *testing.T) {
h := &Handler{
+ appErrorCode: http.StatusInternalServerError,
cfg: &Config{
MaxRequestSize: 1024,
Uploads: &UploadsConfig{
diff --git a/service/http/request.go b/service/http/request.go
index 8da5440f..f3fff198 100644
--- a/service/http/request.go
+++ b/service/http/request.go
@@ -8,7 +8,6 @@ import (
"net/url"
"strings"
- json "github.com/json-iterator/go"
"github.com/sirupsen/logrus"
"github.com/spiral/roadrunner"
"github.com/spiral/roadrunner/service/http/attributes"
@@ -136,13 +135,12 @@ func (r *Request) Close(log *logrus.Logger) {
func (r *Request) Payload() (p *roadrunner.Payload, err error) {
p = &roadrunner.Payload{}
- j := json.ConfigCompatibleWithStandardLibrary
- if p.Context, err = j.Marshal(r); err != nil {
+ if p.Context, err = json.Marshal(r); err != nil {
return nil, err
}
if r.Parsed {
- if p.Body, err = j.Marshal(r.body); err != nil {
+ if p.Body, err = json.Marshal(r.body); err != nil {
return nil, err
}
} else if r.body != nil {
diff --git a/service/http/response.go b/service/http/response.go
index f34754be..a2540edf 100644
--- a/service/http/response.go
+++ b/service/http/response.go
@@ -5,11 +5,12 @@ import (
"net/http"
"strings"
- json "github.com/json-iterator/go"
+ j "github.com/json-iterator/go"
"github.com/spiral/roadrunner"
)
+var json = j.ConfigCompatibleWithStandardLibrary
// Response handles PSR7 response logic.
type Response struct {
@@ -26,8 +27,8 @@ type Response struct {
// NewResponse creates new response based on given rr payload.
func NewResponse(p *roadrunner.Payload) (*Response, error) {
r := &Response{body: p.Body}
- j := json.ConfigCompatibleWithStandardLibrary
- if err := j.Unmarshal(p.Context, r); err != nil {
+
+ if err := json.Unmarshal(p.Context, r); err != nil {
return nil, err
}
diff --git a/service/http/rpc_test.go b/service/http/rpc_test.go
index e57a8699..62f27ede 100644
--- a/service/http/rpc_test.go
+++ b/service/http/rpc_test.go
@@ -1,16 +1,16 @@
package http
import (
- json "github.com/json-iterator/go"
+ "os"
+ "strconv"
+ "testing"
+ "time"
+
"github.com/sirupsen/logrus"
"github.com/sirupsen/logrus/hooks/test"
"github.com/spiral/roadrunner/service"
"github.com/spiral/roadrunner/service/rpc"
"github.com/stretchr/testify/assert"
- "os"
- "strconv"
- "testing"
- "time"
)
func Test_RPC(t *testing.T) {
@@ -88,8 +88,7 @@ func Test_RPC_Unix(t *testing.T) {
c.Register(ID, &Service{})
sock := `unix://` + os.TempDir() + `/rpc.unix`
- j := json.ConfigCompatibleWithStandardLibrary
- data, _ := j.Marshal(sock)
+ data, _ := json.Marshal(sock)
assert.NoError(t, c.Init(&testCfg{
rpcCfg: `{"enable":true, "listen":` + string(data) + `}`,
diff --git a/service/http/service.go b/service/http/service.go
index 25a10064..7a175dcb 100644
--- a/service/http/service.go
+++ b/service/http/service.go
@@ -118,7 +118,12 @@ func (s *Service) Serve() error {
s.rr.Attach(s.controller)
}
- s.handler = &Handler{cfg: s.cfg, rr: s.rr}
+ s.handler = &Handler{
+ cfg: s.cfg,
+ rr: s.rr,
+ internalErrorCode: s.cfg.InternalErrorCode,
+ appErrorCode: s.cfg.AppErrorCode,
+ }
s.handler.Listen(s.throw)
if s.cfg.EnableHTTP() {
diff --git a/service/http/service_test.go b/service/http/service_test.go
index f7ee33cc..960bc513 100644
--- a/service/http/service_test.go
+++ b/service/http/service_test.go
@@ -1,8 +1,13 @@
package http
import (
+ "io/ioutil"
+ "net/http"
+ "os"
+ "testing"
+ "time"
+
"github.com/cenkalti/backoff/v4"
- json "github.com/json-iterator/go"
"github.com/sirupsen/logrus"
"github.com/sirupsen/logrus/hooks/test"
"github.com/spiral/roadrunner"
@@ -10,11 +15,6 @@ import (
"github.com/spiral/roadrunner/service/env"
"github.com/spiral/roadrunner/service/rpc"
"github.com/stretchr/testify/assert"
- "io/ioutil"
- "net/http"
- "os"
- "testing"
- "time"
)
type testCfg struct {
@@ -44,8 +44,7 @@ func (cfg *testCfg) Get(name string) service.Config {
return nil
}
func (cfg *testCfg) Unmarshal(out interface{}) error {
- j := json.ConfigCompatibleWithStandardLibrary
- return j.Unmarshal([]byte(cfg.target), out)
+ return json.Unmarshal([]byte(cfg.target), out)
}
func Test_Service_NoConfig(t *testing.T) {
@@ -752,8 +751,7 @@ func Test_Service_Error4(t *testing.T) {
func tmpDir() string {
p := os.TempDir()
- j := json.ConfigCompatibleWithStandardLibrary
- r, _ := j.Marshal(p)
+ r, _ := json.Marshal(p)
return string(r)
}
diff --git a/service/http/ssl_test.go b/service/http/ssl_test.go
index cf147be9..8078a3a7 100644
--- a/service/http/ssl_test.go
+++ b/service/http/ssl_test.go
@@ -2,14 +2,15 @@ package http
import (
"crypto/tls"
- "github.com/sirupsen/logrus"
- "github.com/sirupsen/logrus/hooks/test"
- "github.com/spiral/roadrunner/service"
- "github.com/stretchr/testify/assert"
"io/ioutil"
"net/http"
"testing"
"time"
+
+ "github.com/sirupsen/logrus"
+ "github.com/sirupsen/logrus/hooks/test"
+ "github.com/spiral/roadrunner/service"
+ "github.com/stretchr/testify/assert"
)
var sslClient = &http.Client{
@@ -245,7 +246,6 @@ func Test_SSL_Service_Push(t *testing.T) {
assert.Equal(t, 201, r.StatusCode)
assert.Equal(t, "WORLD", string(b))
-
err2 := r.Body.Close()
if err2 != nil {
t.Errorf("fail to close the Body: error %v", err2)
diff --git a/service/http/uploads.go b/service/http/uploads.go
index 39a9eaf2..e369fab2 100644
--- a/service/http/uploads.go
+++ b/service/http/uploads.go
@@ -2,13 +2,13 @@ package http
import (
"fmt"
- json "github.com/json-iterator/go"
- "github.com/sirupsen/logrus"
"io"
"io/ioutil"
"mime/multipart"
"os"
"sync"
+
+ "github.com/sirupsen/logrus"
)
const (
@@ -42,8 +42,7 @@ type Uploads struct {
// MarshalJSON marshal tree tree into JSON.
func (u *Uploads) MarshalJSON() ([]byte, error) {
- j := json.ConfigCompatibleWithStandardLibrary
- return j.Marshal(u.tree)
+ return json.Marshal(u.tree)
}
// Open moves all uploaded files to temp directory, return error in case of issue with temp directory. File errors
diff --git a/service/http/uploads_config_test.go b/service/http/uploads_config_test.go
index 2b6ceebc..ac8bfa1d 100644
--- a/service/http/uploads_config_test.go
+++ b/service/http/uploads_config_test.go
@@ -1,9 +1,10 @@
package http
import (
- "github.com/stretchr/testify/assert"
"os"
"testing"
+
+ "github.com/stretchr/testify/assert"
)
func TestFsConfig_Forbids(t *testing.T) {
diff --git a/service/http/uploads_test.go b/service/http/uploads_test.go
index 08177c72..bab20d49 100644
--- a/service/http/uploads_test.go
+++ b/service/http/uploads_test.go
@@ -6,9 +6,6 @@ import (
"crypto/md5"
"encoding/hex"
"fmt"
- json "github.com/json-iterator/go"
- "github.com/spiral/roadrunner"
- "github.com/stretchr/testify/assert"
"io"
"io/ioutil"
"mime/multipart"
@@ -16,6 +13,9 @@ import (
"os"
"testing"
"time"
+
+ "github.com/spiral/roadrunner"
+ "github.com/stretchr/testify/assert"
)
func TestHandler_Upload_File(t *testing.T) {
@@ -424,8 +424,7 @@ func fileString(f string, errNo int, mime string) string {
v.Size = 0
}
- j := json.ConfigCompatibleWithStandardLibrary
- r, err := j.Marshal(v)
+ r, err := json.Marshal(v)
if err != nil {
fmt.Println(fmt.Errorf("error marshalling fInfo, error: %v", err))
}
diff --git a/service/limit/config.go b/service/limit/config.go
index 203db11b..7a56280d 100644
--- a/service/limit/config.go
+++ b/service/limit/config.go
@@ -1,9 +1,10 @@
package limit
import (
+ "time"
+
"github.com/spiral/roadrunner"
"github.com/spiral/roadrunner/service"
- "time"
)
// Config of Limit service.
diff --git a/service/limit/config_test.go b/service/limit/config_test.go
index c79836b8..1f121bc5 100644
--- a/service/limit/config_test.go
+++ b/service/limit/config_test.go
@@ -1,11 +1,12 @@
package limit
import (
+ "testing"
+ "time"
+
json "github.com/json-iterator/go"
"github.com/spiral/roadrunner/service"
"github.com/stretchr/testify/assert"
- "testing"
- "time"
)
type mockCfg struct{ cfg string }
diff --git a/service/limit/controller.go b/service/limit/controller.go
index 24a158f7..b4a1c25f 100644
--- a/service/limit/controller.go
+++ b/service/limit/controller.go
@@ -2,9 +2,10 @@ package limit
import (
"fmt"
+ "time"
+
"github.com/spiral/roadrunner"
"github.com/spiral/roadrunner/util"
- "time"
)
const (
diff --git a/service/limit/state_filter.go b/service/limit/state_filter.go
index cd2eca94..4e05769a 100644
--- a/service/limit/state_filter.go
+++ b/service/limit/state_filter.go
@@ -1,8 +1,9 @@
package limit
import (
- "github.com/spiral/roadrunner"
"time"
+
+ "github.com/spiral/roadrunner"
)
type stateFilter struct {
diff --git a/service/metrics/config_test.go b/service/metrics/config_test.go
index 94f97da5..5153ead1 100644
--- a/service/metrics/config_test.go
+++ b/service/metrics/config_test.go
@@ -11,7 +11,7 @@ import (
type mockCfg struct{ cfg string }
-func (cfg *mockCfg) Get(name string) service.Config { return nil }
+func (cfg *mockCfg) Get(name string) service.Config { return nil }
func (cfg *mockCfg) Unmarshal(out interface{}) error {
j := json.ConfigCompatibleWithStandardLibrary
return j.Unmarshal([]byte(cfg.cfg), out)
diff --git a/service/metrics/rpc_test.go b/service/metrics/rpc_test.go
index 2fc4bc32..37af3eec 100644
--- a/service/metrics/rpc_test.go
+++ b/service/metrics/rpc_test.go
@@ -1,15 +1,16 @@
package metrics
import (
+ rpc2 "net/rpc"
+ "strconv"
+ "testing"
+ "time"
+
"github.com/sirupsen/logrus"
"github.com/sirupsen/logrus/hooks/test"
"github.com/spiral/roadrunner/service"
"github.com/spiral/roadrunner/service/rpc"
"github.com/stretchr/testify/assert"
- rpc2 "net/rpc"
- "strconv"
- "testing"
- "time"
)
var port = 5004
diff --git a/service/metrics/service_test.go b/service/metrics/service_test.go
index cdb81147..7e11cf85 100644
--- a/service/metrics/service_test.go
+++ b/service/metrics/service_test.go
@@ -1,6 +1,11 @@
package metrics
import (
+ "io/ioutil"
+ "net/http"
+ "testing"
+ "time"
+
json "github.com/json-iterator/go"
"github.com/prometheus/client_golang/prometheus"
"github.com/sirupsen/logrus"
@@ -8,10 +13,6 @@ import (
"github.com/spiral/roadrunner/service"
"github.com/spiral/roadrunner/service/rpc"
"github.com/stretchr/testify/assert"
- "io/ioutil"
- "net/http"
- "testing"
- "time"
)
type testCfg struct {
diff --git a/service/reload/config.go b/service/reload/config.go
index efc71972..46267045 100644
--- a/service/reload/config.go
+++ b/service/reload/config.go
@@ -2,9 +2,10 @@ package reload
import (
"errors"
+ "time"
+
"github.com/spiral/roadrunner"
"github.com/spiral/roadrunner/service"
- "time"
)
// Config is a Reload configuration point.
diff --git a/service/reload/config_test.go b/service/reload/config_test.go
index 600975d3..b0620aa1 100644
--- a/service/reload/config_test.go
+++ b/service/reload/config_test.go
@@ -1,9 +1,10 @@
package reload
import (
- "github.com/stretchr/testify/assert"
"testing"
"time"
+
+ "github.com/stretchr/testify/assert"
)
func Test_Config_Valid(t *testing.T) {
diff --git a/service/rpc/config.go b/service/rpc/config.go
index a4cf0f91..cc492622 100644
--- a/service/rpc/config.go
+++ b/service/rpc/config.go
@@ -2,10 +2,11 @@ package rpc
import (
"errors"
- "github.com/spiral/roadrunner/service"
- "github.com/spiral/roadrunner/util"
"net"
"strings"
+
+ "github.com/spiral/roadrunner/service"
+ "github.com/spiral/roadrunner/util"
)
// Config defines RPC service config.
diff --git a/service/rpc/config_test.go b/service/rpc/config_test.go
index 1ecd71b3..70d58e84 100644
--- a/service/rpc/config_test.go
+++ b/service/rpc/config_test.go
@@ -1,10 +1,11 @@
package rpc
import (
+ "testing"
+
json "github.com/json-iterator/go"
"github.com/spiral/roadrunner/service"
"github.com/stretchr/testify/assert"
- "testing"
)
type testCfg struct{ cfg string }
diff --git a/service/rpc/service.go b/service/rpc/service.go
index 7a649f1b..1d6d7595 100644
--- a/service/rpc/service.go
+++ b/service/rpc/service.go
@@ -2,11 +2,12 @@ package rpc
import (
"errors"
+ "net/rpc"
+ "sync"
+
"github.com/spiral/goridge/v2"
"github.com/spiral/roadrunner/service"
"github.com/spiral/roadrunner/service/env"
- "net/rpc"
- "sync"
)
// ID contains default service name.
diff --git a/service/rpc/service_test.go b/service/rpc/service_test.go
index 51c1b337..385e818e 100644
--- a/service/rpc/service_test.go
+++ b/service/rpc/service_test.go
@@ -1,11 +1,12 @@
package rpc
import (
+ "testing"
+ "time"
+
"github.com/spiral/roadrunner/service"
"github.com/spiral/roadrunner/service/env"
"github.com/stretchr/testify/assert"
- "testing"
- "time"
)
type testService struct{}
diff --git a/service/static/config.go b/service/static/config.go
index 3ca20a83..db50c7dd 100644
--- a/service/static/config.go
+++ b/service/static/config.go
@@ -2,10 +2,11 @@ package static
import (
"fmt"
- "github.com/spiral/roadrunner/service"
"os"
"path"
"strings"
+
+ "github.com/spiral/roadrunner/service"
)
// Config describes file location and controls access to them.
diff --git a/service/static/config_test.go b/service/static/config_test.go
index 8bf0d372..2bc936bb 100644
--- a/service/static/config_test.go
+++ b/service/static/config_test.go
@@ -1,10 +1,11 @@
package static
import (
+ "testing"
+
json "github.com/json-iterator/go"
"github.com/spiral/roadrunner/service"
"github.com/stretchr/testify/assert"
- "testing"
)
type mockCfg struct{ cfg string }
diff --git a/service/static/service.go b/service/static/service.go
index 95b99860..49dbedab 100644
--- a/service/static/service.go
+++ b/service/static/service.go
@@ -1,9 +1,10 @@
package static
import (
- rrhttp "github.com/spiral/roadrunner/service/http"
"net/http"
"path"
+
+ rrhttp "github.com/spiral/roadrunner/service/http"
)
// ID contains default service name.
diff --git a/service/static/service_test.go b/service/static/service_test.go
index 842662c9..bbab86c2 100644
--- a/service/static/service_test.go
+++ b/service/static/service_test.go
@@ -2,18 +2,19 @@ package static
import (
"bytes"
- json "github.com/json-iterator/go"
- "github.com/sirupsen/logrus"
- "github.com/sirupsen/logrus/hooks/test"
- "github.com/spiral/roadrunner/service"
- rrhttp "github.com/spiral/roadrunner/service/http"
- "github.com/stretchr/testify/assert"
"io"
"io/ioutil"
"net/http"
"os"
"testing"
"time"
+
+ json "github.com/json-iterator/go"
+ "github.com/sirupsen/logrus"
+ "github.com/sirupsen/logrus/hooks/test"
+ "github.com/spiral/roadrunner/service"
+ rrhttp "github.com/spiral/roadrunner/service/http"
+ "github.com/stretchr/testify/assert"
)
type testCfg struct {
@@ -75,7 +76,6 @@ func Test_Files(t *testing.T) {
time.Sleep(time.Second)
-
b, _, _ := get("http://localhost:8029/sample.txt")
assert.Equal(t, "sample", b)
c.Stop()
@@ -475,7 +475,6 @@ func TestStatic_Headers(t *testing.T) {
t.Fatal("can't find output header in response")
}
-
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
t.Fatal(err)