Documentation
¶
Overview ¶
Package execstream is the wire protocol of `preview exec`: a byte stream of typed frames multiplexing an interactive exec session — stdin, stdout, stderr, terminal resizes, the final exit code, and transport-level errors — over a single bidirectional connection. The same frames ride every hop (CLI ↔ control API ↔ worker API ↔ supervisor), so a control node forwarding a session to a worker copies bytes blindly, without re-framing.
Each frame is a 1-byte type, a 4-byte big-endian payload length, then the payload. The carrier is a WebSocket (see Accept/Dial) treated as a plain byte stream: WebSocket is the one upgrade ALBs and proxies reliably pass through, and the CSRF story (browser-enforced Origin on ws handshakes) comes for free.
Index ¶
- Constants
- func Accept(w http.ResponseWriter, r *http.Request) (net.Conn, error)
- func DecodeResize(p []byte) (cols, rows uint16, err error)
- func Dial(ctx context.Context, url string, header http.Header) (net.Conn, error)
- func ResizePayload(cols, rows uint16) []byte
- type ExitError
- type Frame
- type RemoteError
- type StreamWriter
- type Writer
Constants ¶
const ( FrameStdin byte = iota + 1 FrameStdout FrameStderr // FrameExit carries the command's exit code as one byte (0–255). It is // the last frame of a successful session. FrameExit // FrameResize carries cols then rows, each big-endian uint16. FrameResize // FrameStdinEOF signals the client closed stdin (payload empty); the // executed command sees EOF but the session keeps streaming output. FrameStdinEOF // FrameError carries human-readable text for a session that failed for // transport or orchestration reasons (as opposed to a command exiting // non-zero, which is FrameExit). FrameError // FramePing is a client keep-alive (payload empty) — traffic that stops a // load balancer's idle timeout from severing a quiet session. Receivers // ignore it, as they do any unknown frame type. FramePing )
Frame types. Stdin, StdinEOF, and Resize flow client→server; Stdout, Stderr, Exit, and Error flow server→client.
const MaxPayload = 1 << 20
MaxPayload bounds one frame's payload, and so the allocation a peer can force per frame. Writers chunk larger payloads across frames.
Variables ¶
This section is empty.
Functions ¶
func Accept ¶
Accept upgrades an HTTP request to the exec byte stream. It clears the server's per-request deadlines first — an interactive session outlives any ReadTimeout — and returns a net.Conn carrying the frame protocol. The WebSocket handshake enforces same-origin for browser callers; non-browser clients (the CLI, a control node) send no Origin and pass.
func DecodeResize ¶
DecodeResize decodes a FrameResize payload.
func Dial ¶
Dial opens the exec byte stream against url (http/https, or ws/wss), sending header on the handshake. A failed handshake surfaces the HTTP response body when there is one — that's where the API's JSON error lands.
func ResizePayload ¶
ResizePayload encodes a terminal size for FrameResize.
Types ¶
type ExitError ¶
type ExitError struct{ Code int }
ExitError is a session that ended with the command exiting non-zero — distinct from transport failures so callers can propagate the code.
type RemoteError ¶
type RemoteError struct{ Msg string }
RemoteError is a FrameError received from the peer.
func (RemoteError) Error ¶
func (e RemoteError) Error() string
type StreamWriter ¶
StreamWriter adapts one frame type to io.Writer — the output pumps copy into these.