summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.changes1
-rw-r--r--cmd/cli/reset.go3
-rw-r--r--cmd/cli/root.go7
-rw-r--r--cmd/cli/version.go4
-rw-r--r--dput.cf5
-rw-r--r--plugins/http/config.go5
-rw-r--r--plugins/http/constants.go2
-rw-r--r--plugins/http/handler.go29
-rw-r--r--plugins/http/plugin.go12
-rw-r--r--plugins/server/config.go1
-rw-r--r--plugins/server/interface.go1
-rw-r--r--plugins/server/plugin.go3
-rw-r--r--tests/plugins/http/response_test.go4
13 files changed, 50 insertions, 27 deletions
diff --git a/.changes b/.changes
new file mode 100644
index 00000000..345e6aef
--- /dev/null
+++ b/.changes
@@ -0,0 +1 @@
+Test
diff --git a/cmd/cli/reset.go b/cmd/cli/reset.go
index 03b470e5..504d88ad 100644
--- a/cmd/cli/reset.go
+++ b/cmd/cli/reset.go
@@ -12,7 +12,10 @@ import (
"github.com/vbauerster/mpb/v5/decor"
)
+// List is the resetter.List RPC method
const List string = "resetter.List"
+
+// Reset is the resetter.Reset RPC method
const Reset string = "resetter.Reset"
func init() {
diff --git a/cmd/cli/root.go b/cmd/cli/root.go
index 7b18a22f..06a84a82 100644
--- a/cmd/cli/root.go
+++ b/cmd/cli/root.go
@@ -17,8 +17,11 @@ import (
)
var (
- WorkDir string
- CfgFile string
+ // WorkDir is working directory
+ WorkDir string
+ // CfgFile is path to the .rr.yaml
+ CfgFile string
+ // Container is the pointer to the Endure container
Container *endure.Endure
cfg *config.Viper
root = &cobra.Command{
diff --git a/cmd/cli/version.go b/cmd/cli/version.go
index 6a259668..89728bd2 100644
--- a/cmd/cli/version.go
+++ b/cmd/cli/version.go
@@ -2,8 +2,8 @@ package cli
var (
// Version - defines build version.
- Version string = "local" //nolint:deadcode
+ Version string = "local"
// BuildTime - defined build time.
- BuildTime string = "development" //nolint:deadcode
+ BuildTime string = "development"
)
diff --git a/dput.cf b/dput.cf
new file mode 100644
index 00000000..818b9507
--- /dev/null
+++ b/dput.cf
@@ -0,0 +1,5 @@
+[roadrunner]
+fqdn = ppa.launchpad.net
+method = ftp
+incoming = 48d90782/ubuntu/roadrunner
+login = anonymous
diff --git a/plugins/http/config.go b/plugins/http/config.go
index 00d2940b..3b670c86 100644
--- a/plugins/http/config.go
+++ b/plugins/http/config.go
@@ -11,8 +11,10 @@ import (
poolImpl "github.com/spiral/roadrunner/v2/pkg/pool"
)
+// Cidrs is a slice of IPNet addresses
type Cidrs []*net.IPNet
+// IsTrusted checks if the ip address exists in the provided in the config addresses
func (c *Cidrs) IsTrusted(ip string) bool {
if len(*c) == 0 {
return false
@@ -137,7 +139,7 @@ func (c *Config) EnableFCGI() bool {
return c.FCGI.Address != ""
}
-// Hydrate must populate Config values using given Config source. Must return error if Config is not valid.
+// InitDefaults must populate Config values using given Config source. Must return error if Config is not valid.
func (c *Config) InitDefaults() error {
if c.Pool == nil {
// default pool
@@ -202,6 +204,7 @@ func (c *Config) InitDefaults() error {
return c.Valid()
}
+// ParseCIDRs parse IPNet addresses and return slice of its
func ParseCIDRs(subnets []string) (Cidrs, error) {
c := make(Cidrs, 0, len(subnets))
for _, cidr := range subnets {
diff --git a/plugins/http/constants.go b/plugins/http/constants.go
index 773d1f46..c3d5c589 100644
--- a/plugins/http/constants.go
+++ b/plugins/http/constants.go
@@ -3,4 +3,6 @@ package http
import "net/http"
var http2pushHeaderKey = http.CanonicalHeaderKey("http2-push")
+
+// TrailerHeaderKey http header key
var TrailerHeaderKey = http.CanonicalHeaderKey("trailer")
diff --git a/plugins/http/handler.go b/plugins/http/handler.go
index 15954f96..9c40cdfc 100644
--- a/plugins/http/handler.go
+++ b/plugins/http/handler.go
@@ -23,13 +23,9 @@ const (
EventError
)
+// MB is 1024 bytes
const MB = 1024 * 1024
-type Handle interface {
- AddListener(l events.Listener)
- ServeHTTP(w http.ResponseWriter, r *http.Request)
-}
-
// ErrorEvent represents singular http error event.
type ErrorEvent struct {
// Request contains client request, must not be stored.
@@ -68,7 +64,7 @@ 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 {
+type Handler struct {
maxRequestSize uint64
uploads UploadsConfig
trusted Cidrs
@@ -78,11 +74,12 @@ type handler struct {
lsn events.Listener
}
-func NewHandler(maxReqSize uint64, uploads UploadsConfig, trusted Cidrs, pool pool.Pool) (Handle, error) {
+// NewHandler return handle interface implementation
+func NewHandler(maxReqSize uint64, uploads UploadsConfig, trusted Cidrs, pool pool.Pool) (*Handler, error) {
if pool == nil {
return nil, errors.E(errors.Str("pool should be initialized"))
}
- return &handler{
+ return &Handler{
maxRequestSize: maxReqSize * MB,
uploads: uploads,
pool: pool,
@@ -90,8 +87,8 @@ func NewHandler(maxReqSize uint64, uploads UploadsConfig, trusted Cidrs, pool po
}, nil
}
-// Listen attaches handler event controller.
-func (h *handler) AddListener(l events.Listener) {
+// AddListener attaches handler event controller.
+func (h *Handler) AddListener(l events.Listener) {
h.mul.Lock()
defer h.mul.Unlock()
@@ -99,7 +96,7 @@ func (h *handler) AddListener(l events.Listener) {
}
// mdwr serve using PSR-7 requests passed to underlying application. Attempts to serve static files first if enabled.
-func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
const op = errors.Op("ServeHTTP")
start := time.Now()
@@ -148,7 +145,7 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
}
-func (h *handler) maxSize(w http.ResponseWriter, r *http.Request, start time.Time, op errors.Op) error {
+func (h *Handler) maxSize(w http.ResponseWriter, r *http.Request, start time.Time, op errors.Op) error {
if length := r.Header.Get("content-length"); length != "" {
if size, err := strconv.ParseInt(length, 10, 64); err != nil {
h.handleError(w, r, err, start)
@@ -162,7 +159,7 @@ func (h *handler) maxSize(w http.ResponseWriter, r *http.Request, start time.Tim
}
// handleError sends error.
-func (h *handler) handleError(w http.ResponseWriter, r *http.Request, err error, start time.Time) {
+func (h *Handler) handleError(w http.ResponseWriter, r *http.Request, err error, start time.Time) {
h.mul.Lock()
defer h.mul.Unlock()
// if pipe is broken, there is no sense to write the header
@@ -186,19 +183,19 @@ func (h *handler) handleError(w http.ResponseWriter, r *http.Request, err error,
}
// handleResponse triggers response event.
-func (h *handler) handleResponse(req *Request, resp *Response, start time.Time) {
+func (h *Handler) handleResponse(req *Request, resp *Response, start time.Time) {
h.throw(ResponseEvent{Request: req, Response: resp, start: start, elapsed: time.Since(start)})
}
// throw invokes event handler if any.
-func (h *handler) throw(event interface{}) {
+func (h *Handler) throw(event interface{}) {
if h.lsn != nil {
h.lsn(event)
}
}
// get real ip passing multiple proxy
-func (h *handler) resolveIP(r *Request) {
+func (h *Handler) resolveIP(r *Request) {
if h.trusted.IsTrusted(r.RemoteAddr) == false {
return
}
diff --git a/plugins/http/plugin.go b/plugins/http/plugin.go
index 2651f305..e6aba78b 100644
--- a/plugins/http/plugin.go
+++ b/plugins/http/plugin.go
@@ -44,7 +44,7 @@ type Middleware interface {
type middleware map[string]Middleware
-// Service manages pool, http servers.
+// Plugin manages pool, http servers. The main http plugin structure
type Plugin struct {
sync.RWMutex
@@ -60,7 +60,7 @@ type Plugin struct {
pool pool.Pool
// servers RR handler
- handler Handle
+ handler *Handler
// servers
http *http.Server
@@ -267,15 +267,17 @@ func (s *Plugin) ServeHTTP(w http.ResponseWriter, r *http.Request) {
s.RUnlock()
}
-// Server returns associated pool workers
+// Workers returns associated pool workers
func (s *Plugin) Workers() []worker.BaseProcess {
return s.pool.Workers()
}
+// Name returns endure.Named interface implementation
func (s *Plugin) Name() string {
return PluginName
}
+// Reset destroys the old pool and replaces it with new one, waiting for old pool to die
func (s *Plugin) Reset() error {
s.Lock()
defer s.Unlock()
@@ -319,12 +321,14 @@ func (s *Plugin) Reset() error {
return nil
}
+// Collects collecting http middlewares
func (s *Plugin) Collects() []interface{} {
return []interface{}{
s.AddMiddleware,
}
}
+// AddMiddleware is base requirement for the middleware (name and Middleware)
func (s *Plugin) AddMiddleware(name endure.Named, m Middleware) {
s.mdwr[name.Name()] = m
}
@@ -414,7 +418,7 @@ func (s *Plugin) initSSL() *http.Server {
hasGCMAsm := hasGCMAsmAMD64 || hasGCMAsmARM64 || hasGCMAsmS390X
if hasGCMAsm {
- // If AES-GCM hardware is provided then prioritise AES-GCM
+ // If AES-GCM hardware is provided then priorities AES-GCM
// cipher suites.
topCipherSuites = []uint16{
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
diff --git a/plugins/server/config.go b/plugins/server/config.go
index 4bef3c5f..2bf30e70 100644
--- a/plugins/server/config.go
+++ b/plugins/server/config.go
@@ -28,6 +28,7 @@ type Config struct {
RelayTimeout time.Duration
}
+// InitDefaults for the server config
func (cfg *Config) InitDefaults() {
if cfg.Relay == "" {
cfg.Relay = "pipes"
diff --git a/plugins/server/interface.go b/plugins/server/interface.go
index 98345694..a2d8b92b 100644
--- a/plugins/server/interface.go
+++ b/plugins/server/interface.go
@@ -10,6 +10,7 @@ import (
poolImpl "github.com/spiral/roadrunner/v2/pkg/pool"
)
+// Env variables type alias
type Env map[string]string
// Server creates workers for the application.
diff --git a/plugins/server/plugin.go b/plugins/server/plugin.go
index 5d1f26d3..8a843723 100644
--- a/plugins/server/plugin.go
+++ b/plugins/server/plugin.go
@@ -21,6 +21,7 @@ import (
"github.com/spiral/roadrunner/v2/utils"
)
+// PluginName for the server
const PluginName = "server"
// Plugin manages worker
@@ -53,11 +54,13 @@ func (server *Plugin) Name() string {
return PluginName
}
+// Serve (Start) server plugin (just a mock here to satisfy interface)
func (server *Plugin) Serve() chan error {
errCh := make(chan error, 1)
return errCh
}
+// Stop used to close chosen in config factory
func (server *Plugin) Stop() error {
if server.factory == nil {
return nil
diff --git a/tests/plugins/http/response_test.go b/tests/plugins/http/response_test.go
index a9cbf91a..9bd2626d 100644
--- a/tests/plugins/http/response_test.go
+++ b/tests/plugins/http/response_test.go
@@ -138,8 +138,8 @@ func TestWrite_HandlesTrailers(t *testing.T) {
assert.NoError(t, r.Write(w))
assert.Nil(t, w.h[httpPlugin.TrailerHeaderKey])
- assert.Nil(t, w.h["foo"]) //nolint:golint,staticcheck
- assert.Nil(t, w.h["baz"]) //nolint:golint,staticcheck
+ assert.Nil(t, w.h["foo"]) //nolint:staticcheck
+ assert.Nil(t, w.h["baz"]) //nolint:staticcheck
assert.Equal(t, "test", w.h.Get("Trailer:foo"))
assert.Equal(t, "demo", w.h.Get("Trailer:bar"))