Documentation
¶
Overview ¶
Package httpx provides shared HTTP server lifecycle helpers so that cocoonstack binaries don't each reinvent graceful-shutdown plumbing.
Index ¶
Constants ¶
const DefaultReadHeaderTimeout = 10 * time.Second
DefaultReadHeaderTimeout is the conservative default for http.Server.ReadHeaderTimeout. 10s is what every cocoonstack consumer was already using and mitigates Slowloris attacks (gosec G112) by capping how long a client may take to send headers.
Variables ¶
This section is empty.
Functions ¶
func NewServer ¶
NewServer returns an *http.Server with Addr, Handler, and the safe ReadHeaderTimeout default set. Use this in preference to composing an http.Server literal so every server in the stack carries the same Slowloris-mitigation timeout.
func Run ¶
Run starts every spec in its own goroutine and blocks until ctx is canceled or any spec's Start returns a non-ErrServerClosed error. On exit it calls Shutdown on each server using a fresh timeout context that is *not* derived from the canceled parent (shutdown must outlive the signal-derived ctx). Errors from both serve and shutdown are aggregated with errors.Join. http.ErrServerClosed is treated as a clean shutdown and never returned.
Types ¶
type ServerSpec ¶
ServerSpec pairs an http.Server with the StartFunc that boots it. Start is called in a goroutine; Server is what Run calls Shutdown on when the parent context is canceled.
func HTTPSServerSpec ¶
func HTTPSServerSpec(srv *http.Server, cert, key string) ServerSpec
HTTPSServerSpec wraps srv with srv.ListenAndServeTLS(cert, key) as its StartFunc. If cert and key are empty, the server is expected to have its TLSConfig.Certificates populated and srv.ListenAndServeTLS("", "") will still work.
func HTTPServerSpec ¶
func HTTPServerSpec(srv *http.Server) ServerSpec
HTTPServerSpec wraps srv with srv.ListenAndServe as its StartFunc.