httpapi

package
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 29 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	CloseSlowConsumer  websocket.StatusCode = 4000
	CloseReplayGap     websocket.StatusCode = 4001
	CloseUnauthorized  websocket.StatusCode = 4003
	CloseInputOverflow websocket.StatusCode = 4004
)

Application close codes.

View Source
const TerminalProtocol = "webpty.terminal.v1"

TerminalProtocol is the WebSocket subprotocol clients must offer.

Variables

This section is empty.

Functions

func NewRouter

func NewRouter(options ...Option) http.Handler

Types

type Drain

type Drain struct {
	// contains filtered or unexported fields
}

Drain tracks in-flight requests, including WebSocket handlers whose connections http.Server no longer tracks once hijacked, so shutdown can cancel them and wait before closing what they use.

func NewDrain

func NewDrain() *Drain

NewDrain returns an open Drain.

func (*Drain) Close

func (d *Drain) Close(ctx context.Context) error

Close rejects new requests, cancels in-flight ones, and waits until they return or ctx is done. It is idempotent.

func (*Drain) Wrap

func (d *Drain) Wrap(next http.Handler) http.Handler

Wrap counts next's requests. Each request's context is also cancelled by Close; requests arriving after Close get 503.

type Option

type Option func(*http.ServeMux)

Option configures the router.

func WithAdminAuth

func WithAdminAuth(service *auth.Service, security SecuritySettings, guests ...*access.Service) Option

WithAdminAuth mounts the administrator authentication API. When guests is given, signing out also revokes the browser's access session.

func WithConsole

func WithConsole(service *auth.Service, security SecuritySettings, db *store.Store, settings []Setting) Option

WithConsole mounts the admin audit log and the read-only runtime settings.

func WithRecordings

func WithRecordings(service *auth.Service, security SecuritySettings, recordings *recording.Service) Option

WithRecordings mounts the admin recording API: metadata, validated playback, asciicast export, deletion, and retention.

func WithSPA

func WithSPA(files fs.FS, secureCookies bool) Option

WithSPA serves the embedded single-page application for /, /admin, and /join. Vite's content-hashed /assets are cached immutably; the HTML shell is revalidated on every load. API routes are more specific and win. secureCookies also enables the HSTS response header on document loads.

func WithTerminals

func WithTerminals(service *auth.Service, security SecuritySettings, manager *session.Manager, settings TerminalSettings) Option

WithTerminals mounts the admin terminal REST API and the terminal WebSocket, plus the capability-grant routes when settings.Access is set.

type SecuritySettings

type SecuritySettings struct {
	// PublicOrigin, when set, is the only origin accepted for mutating
	// requests. Otherwise requests must target a loopback Host and mutating
	// requests must originate from that same Host, which defeats DNS
	// rebinding against local installations.
	PublicOrigin  string
	SecureCookies bool
}

SecuritySettings control cookie and origin policy.

type Setting

type Setting struct {
	Key             string `json:"key"`
	Group           string `json:"group"`
	Label           string `json:"label"`
	Value           string `json:"value"`
	RestartRequired bool   `json:"restartRequired"`
}

Setting is one sanitized runtime configuration value shown to the administrator. Values must never include credentials, tokens, or command arguments.

type TerminalSettings

type TerminalSettings struct {
	// WriteTimeout bounds each WebSocket message write.
	WriteTimeout time.Duration
	// PingInterval is how often the peer is probed and the admin session
	// re-validated.
	PingInterval time.Duration
	// Heartbeat returns the ticks that drive each connection's heartbeat
	// and a function that stops them. A time.Ticker is used when nil.
	Heartbeat func(interval time.Duration) (<-chan time.Time, func())
	// MaxMessageBytes limits one client WebSocket message.
	MaxMessageBytes int64
	// InputQueueBytes bounds input one connection may have waiting for the
	// PTY. A client that exceeds it is closed with CloseInputOverflow. One
	// message is always accepted into an empty queue, whatever its size.
	InputQueueBytes int
	// TerminateTimeout bounds how long DELETE waits for the process to exit.
	TerminateTimeout time.Duration
	// Access, when set, enables capability grants: the admin grant routes,
	// guest redemption and sessions, and guest WebSocket connections.
	Access *access.Service
	// Presence tracks participants; a private hub is used when nil.
	Presence *collab.Hub
	// Recordings, when set, warns owners over the WebSocket when the
	// terminal's recording stops early. Guests are never told.
	Recordings *recording.Service
	// RedeemThrottle limits invitation redemption attempts per client.
	RedeemThrottle *auth.Throttle
	Logger         *slog.Logger
}

TerminalSettings tune the terminal transport. Zero fields receive defaults.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL