Documentation
¶
Overview ¶
Package httpsrv is the listener plumbing behind the hub's four endpoints (tunnel, admin, proxy, metrics). It gives them one server shape — h2c, with the timeouts a public-facing listener needs — one place to start them, and one place to drain them on shutdown.
A Group owns the servers it starts, so the hub command reads as the list of listeners it brings up:
g := httpsrv.NewGroup(logger)
if err := g.Start(ctx, "tunnel", addr, handler, httpsrv.MaxConns(n)); err != nil {
return err
}
...
forced := g.Drain(5 * time.Second)
Start binds synchronously and serves in the background, so a port already in use fails at boot with the address in the error, while a serve error later in the process's life is logged under the listener's name.
Every listener here is plaintext: transport encryption is the deployment's job (a TLS edge, ingress, or mesh in front of the hub).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HostGuard ¶
HostGuard rejects requests whose Host header is not allow-listed, which is what stops a DNS-rebinding page from driving the plaintext, loopback-served console and its token-minting endpoint. Loopback names are always allowed; a deployment exposed through a proxy adds its public hostname. A single "*" entry disables the check.
Types ¶
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group starts HTTP listeners and drains them together. Start it from one goroutine (a boot sequence) and Drain it after: the group is not safe for concurrent Starts.
func NewGroup ¶
NewGroup returns an empty group. Serve errors are logged to logger under the name each listener was started with.
func (*Group) Drain ¶
Drain shuts every started listener down gracefully, giving in-flight requests up to grace to finish. It reports whether a second signal (a second Ctrl-C during the grace period) forced the close instead: the caller decides what to say about that, Drain only decides when to stop waiting.
The parent context already consumed the first signal, so Drain re-arms its own handler for the duration of the drain.
func (*Group) Start ¶
func (g *Group) Start(ctx context.Context, name, addr string, handler http.Handler, opts ...Option) error
Start binds addr and serves handler on it in the background. The bind happens before returning, so an address in use is reported here; name labels the listener in any later serve error.