Documentation ¶
Overview ¶
Package httpserver implements a HTTP/HTTPS/HTTP3 server for darvaza sidecars.
Index ¶
- Constants
- Variables
- func AcmeHTTP01Middleware(next, acme http.Handler) http.Handler
- type BindingConfig
- type Config
- type Listeners
- type Server
- func (srv *Server) Cancel(cause error)
- func (srv *Server) Close() error
- func (srv *Server) HasInsecure() bool
- func (srv *Server) HasSecure() bool
- func (srv *Server) ListenWithListener(lc bind.TCPUDPListener) error
- func (srv *Server) NewH2CHandler(h http.Handler) http.Handler
- func (srv *Server) NewH2CServer(h http.Handler, addr net.Addr) *http.Server
- func (srv *Server) NewH2Handler(h http.Handler) http.Handler
- func (srv *Server) NewH2Server(h http.Handler, addr net.Addr) (*http.Server, error)
- func (srv *Server) NewH3Handler(h http.Handler) http.Handler
- func (*Server) NewH3Server(h http.Handler, addr net.Addr) *http3.Server
- func (srv *Server) NewHTTPSRedirectHandler() http.Handler
- func (srv *Server) NewHTTPServer(proto string, addr net.Addr) *http.Server
- func (srv *Server) NewHTTPServerErrorLogger(proto string, addr net.Addr) *log.Logger
- func (*Server) NewQUICConfig() *quic.Config
- func (srv *Server) NewTLSConfig() *tls.Config
- func (srv *Server) QUICHeadersMiddleware(next http.Handler) http.Handler
- func (srv *Server) Serve(h http.Handler) error
- func (srv *Server) SetQUICHeaders(hdr http.Header) error
- func (srv *Server) Spawn(h http.Handler, wait time.Duration) error
- func (srv *Server) Wait() error
Constants ¶
const ( // AltSvcHeader is the header label used to advertise // QUIC support AltSvcHeader = "Alt-Svc" // GrabQUICHeadersRetry indicates how long we wait to // grab the generated Alt-Svc header GrabQUICHeadersRetry = 10 * time.Millisecond )
const ( // DefaultSecurePort represents the default port for secure HTTP (TCP and UDP) DefaultSecurePort = 443 // DefaultInsecurePort represents the default port for plain HTTP (TCP) DefaultInsecurePort = 80 )
Variables ¶
var AcmeHTTP01Pattern = glob.MustCompile("/.well-known/acme-challenge{/(*),/**,}", '/')
AcmeHTTP01Pattern matches ACME-HTTP-01 tokens
Functions ¶
func AcmeHTTP01Middleware ¶ added in v0.3.1
AcmeHTTP01Middleware adds middleware to handle HTTP-01 challenges. if called without ACME handler or to a path without a valid token 404 will be returned automatically instead of passing the request to the next handler.
Types ¶
type BindingConfig ¶
type BindingConfig struct { Addrs []netip.Addr Port uint16 PortInsecure uint16 PortStrict bool PortAttempts int // EnableInsecure makes us listen the plain HTTP port EnableInsecure bool // AllowInsecure makes us handle plain HTTP requests // instead of simply redirecting to the HTTPS port. AllowInsecure bool }
BindingConfig describes what the Server will listen.
type Config ¶
type Config struct { Context context.Context Logger slog.Logger Bind BindingConfig TLSConfig *tls.Config // AcmeHTTP01 is an optional [http.Handler] that will // receive requests for /.well-known/acme-challenge // with a valid token. // // If no handler is specified, the server will // automatically emit a 404 error for requests // against this well-known path. AcmeHTTP01 http.Handler ReadTimeout time.Duration ReadHeaderTimeout time.Duration WriteTimeout time.Duration IdleTimeout time.Duration GracefulTimeout time.Duration }
Config describes how the Server will be assembled and operate.
func (*Config) New ¶
New creates a new Server from the Config, optionally taking a shared core.ErrGroup for cancellations.
func (*Config) SetDefaults ¶
SetDefaults fills gaps in the Config.
type Listeners ¶
type Listeners struct { Secure []net.Listener Insecure []*net.TCPListener QUIC []*quic.EarlyListener // contains filtered or unexported fields }
Listeners contains the listeners to be used by this HTTP server.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is an HTTP/1, HTTP/2, HTTP/3 server built around a shared core.ErrGroup.
func (*Server) Close ¶
Close tries to initiate a cancellation if the server is running, and closes all listeners. Errors are ignored.
func (*Server) HasInsecure ¶
HasInsecure tells if the Server will handle plain HTTP requests.
func (*Server) ListenWithListener ¶
func (srv *Server) ListenWithListener(lc bind.TCPUDPListener) error
ListenWithListener uses a given bind.TCPUDPListener to listen to the addresses specified on the Config.
func (*Server) NewH2CHandler ¶
NewH2CHandler returns the http.Handler to use on the H2C server.
func (*Server) NewH2CServer ¶
NewH2CServer creates a new H2C capable http.Server.
func (*Server) NewH2Handler ¶
NewH2Handler returns the http.Handler to use on the H2 server.
func (*Server) NewH2Server ¶
NewH2Server creates a new HTTP/2 capable http.Server.
func (*Server) NewH3Handler ¶ added in v0.3.1
NewH3Handler returns the http.Handler to use on the H3 server.
func (*Server) NewH3Server ¶
NewH3Server creates a new http3.Server.
func (*Server) NewHTTPSRedirectHandler ¶
NewHTTPSRedirectHandler creates a new handler that redirects everything to https.
func (*Server) NewHTTPServer ¶
NewHTTPServer creates a new http.Server.
func (*Server) NewHTTPServerErrorLogger ¶ added in v0.3.1
NewHTTPServerErrorLogger produces a standard log.Logger use the Server's slog.Logger to be used by http.Server to log errors.
func (*Server) NewQUICConfig ¶ added in v0.6.0
func (*Server) NewQUICConfig() *quic.Config
NewQUICConfig returns the quic.Config to be used on the http3.Server.
func (*Server) NewTLSConfig ¶
NewTLSConfig returns the tls.Config to be used on the Server.
func (*Server) QUICHeadersMiddleware ¶ added in v0.6.0
QUICHeadersMiddleware creates a middleware function that injects Alt-Svc on the http.Response headers.
func (*Server) SetQUICHeaders ¶ added in v0.6.0
SetQUICHeaders appends QUIC's Alt-Svc to the http.Response headers.