caddyhttp: Add support for listener wrapper modules

Wrapping listeners is useful for composing custom behavior related
to accepting, closing, reading/writing connections (etc) below the
application layer; for example, the PROXY protocol.
This commit is contained in:
Matthew Holt 2020-03-15 21:26:17 -06:00
parent 0433f9d075
commit f596fd77bb
No known key found for this signature in database
GPG key ID: 2A349DD577D586A5
3 changed files with 87 additions and 0 deletions

View file

@ -16,6 +16,7 @@ package caddyhttp
import (
"context"
"encoding/json"
"fmt"
"net"
"net/http"
@ -38,6 +39,10 @@ type Server struct {
// that may include port ranges.
Listen []string `json:"listen,omitempty"`
// A list of listener wrapper modules, which can modify the behavior
// of the base listener. They are applied in the given order.
ListenerWrappersRaw []json.RawMessage `json:"listener_wrappers,omitempty" caddy:"namespace=caddy.listeners inline_key=wrapper"`
// How long to allow a read from a client's upload. Setting this
// to a short, non-zero value can mitigate slowloris attacks, but
// may also affect legitimately slow clients.
@ -106,6 +111,7 @@ type Server struct {
primaryHandlerChain Handler
errorHandlerChain Handler
listenerWrappers []caddy.ListenerWrapper
tlsApp *caddytls.TLS
logger *zap.Logger