Documentation
¶
Index ¶
- type Client
- type Option
- func WithBearerToken(token string) Option
- func WithHTTPClient(httpClient *http.Client) Option
- func WithHeader(key, value string) Option
- func WithKeepalive(every time.Duration) Option
- func WithLogger(logger *zap.Logger) Option
- func WithRequestHook(hook reqlog.Hook) Option
- func WithTunnelTLS(cfg *tls.Config) Option
- func WithVersion(version string) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the assembled peer: a persistent attach loop that dials the hub and serves an http.Handler back through the tunnel, redialing with jittered backoff. It is NewServer's counterpart for the client side — a thin veneer over the dial package's attach loop.
c := holt.NewClient("wss://hub.example.com/attach", handler,
holt.WithBearerToken(token),
)
err := c.Run(ctx) // attaches, serves, redials; cancel ctx to stop
func New ¶
New wires a peer that attaches to the hub's tunnel endpoint at hubURL — ws:// or wss:// (http/https are accepted as aliases) — and serves handler over the tunnel, as if it were a normal HTTP server. Nothing dials until Run.
type Option ¶
type Option interface{ ApplyClient(*Client) }
Option configures a Client; every SharedOption is one too.
func WithBearerToken ¶
WithBearerToken sends token as the Authorization bearer on the attach request — the counterpart of the server's WithAuthBearer.
func WithHTTPClient ¶
WithHTTPClient overrides the client used for the upgrade request (custom roots, proxies). Default http.DefaultClient.
func WithHeader ¶
WithHeader adds a header to the WebSocket upgrade request — whatever the edge in front of the hub wants (e.g. CF-Access-Client-Id / CF-Access-Client-Secret). Repeatable.
func WithKeepalive ¶
WithKeepalive paces WebSocket-level pings so proxies with idle timeouts keep a quiet tunnel open. Default dial.DefaultKeepalive; a negative value disables them (the inner HTTP/2 PING remains).
func WithLogger ¶
WithLogger sets the logger. Default: no logging.
func WithRequestHook ¶ added in v0.36.0
WithRequestHook reports every request the handler served over the tunnel, once the response is done. See reqlog.Hook.
func WithTunnelTLS ¶
WithTunnelTLS encrypts the payload end-to-end INSIDE the tunnel: after the plaintext holt handshake the peer runs a TLS server over the stream and serves the handler over HTTPS. The hub must dial with a matching client config (hub.WithPeerTLS). Independent of any TLS on the outer WebSocket hop.
func WithVersion ¶
WithVersion sets the peer build version sent in Hello (observability).