summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-01-05 00:18:44 +0300
committerValery Piashchynski <[email protected]>2021-01-05 00:18:44 +0300
commit877b0ed461c7d5e1de87b7561f414aeb236cf3ec (patch)
tree2afdf6fa505f91043e4f22bfc7229d691e3da1d5 /plugins
parent984953a9db1d94817bda2e3d9266583151b1b437 (diff)
Add dput.cf file for the ubuntu launchpad
Add a lot of comments to the exported functions
Diffstat (limited to 'plugins')
-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
7 files changed, 32 insertions, 21 deletions
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