Documentation
¶
Index ¶
- Constants
- func BuildRequestHead(method, target, host string, h http.Header, contentLength int64) ([]byte, error)
- func CopyBody(dst BodyWriter, src io.Reader, buf []byte) (int64, error)
- func ReadControlMessage(r io.Reader, m proto.Message) error
- func ReadPreamble(r io.Reader) (*livekit.AgentHttp_StreamPreamble, error)
- func StreamCode(c livekit.AgentHttp_HttpStreamResetCode) webtransport.StreamErrorCode
- func StripReservedHeaders(h http.Header)
- func WriteControlMessage(w io.Writer, m proto.Message) error
- func WritePreamble(w io.Writer, p *livekit.AgentHttp_StreamPreamble) error
- type BodyWriter
- type Completion
- type CompletionError
- type SourceError
Constants ¶
const ( // MaxPreambleSize bounds the one allocation a peer can size before any HTTP // bytes are parsed. MaxPreambleSize = 64 << 10 MaxRequestHeadSize = 1 << 20 BodyChunkSize = 32 << 10 // ReservedHeaderPrefix namespaces the in-band signalling below. ReservedHeaderPrefix = "x-lk-" )
const CurrentProtocol uint32 = 1
CurrentProtocol is the data-plane protocol version this implementation speaks, negotiated in RegisterWorkerResponse.
const MaxControlMessageSize = 1 << 20
MaxControlMessageSize bounds one framed control message so a malformed length prefix cannot make the reader allocate without bound.
const MinProtocol uint32 = 1
MinProtocol is the oldest data-plane protocol version still served.
const SessionCloseOK = 0
SessionCloseOK is the WebTransport application close code for a normal session teardown; the human-readable reason travels in the close message.
Variables ¶
This section is empty.
Functions ¶
func BuildRequestHead ¶
func BuildRequestHead(method, target, host string, h http.Header, contentLength int64) ([]byte, error)
BuildRequestHead serializes the canonical origin-form request head.
Its inputs must come from an already-parsed request, never from the client's own bytes: emitting a head this side has parsed is what keeps request smuggling out of the worker.
contentLength >= 0 is framed with Content-Length; a negative length is framed chunked, the only framing that can carry completion trailers.
func CopyBody ¶
CopyBody pumps src into dst one write per read, so a streaming body stays incremental. A src failure is wrapped in *SourceError; any other error is from dst.
func ReadControlMessage ¶
ReadControlMessage reads one length-delimited protobuf written by WriteControlMessage into m.
func ReadPreamble ¶
func ReadPreamble(r io.Reader) (*livekit.AgentHttp_StreamPreamble, error)
func StreamCode ¶
func StreamCode(c livekit.AgentHttp_HttpStreamResetCode) webtransport.StreamErrorCode
StreamCode converts a protocol reset code to the WebTransport code that carries it. HSR_ABORT is zero, so a teardown with nothing to say sends the plain cancel code.
func StripReservedHeaders ¶
StripReservedHeaders removes the in-band signalling fields. Every header set crossing between client and worker must pass through here: a client-set x-lk-completion would otherwise forge an outcome, and a worker-set one would reach the end client.
func WriteControlMessage ¶
WriteControlMessage writes a length-delimited protobuf on the control stream: a 4-byte big-endian length followed by the marshaled message. The stream carries the WorkerMessage/ServerMessage exchange.
func WritePreamble ¶
func WritePreamble(w io.Writer, p *livekit.AgentHttp_StreamPreamble) error
WritePreamble writes the stream preamble. Everything after it is opaque HTTP/1.1.
Types ¶
type BodyWriter ¶
type BodyWriter interface {
io.Writer
Close(c Completion, reason string) error
}
BodyWriter frames one body onto a stream. Close ends the body; a completion other than success is reported in trailers where the framing allows it.
func NewChunkedBody ¶
func NewChunkedBody(w io.Writer) BodyWriter
NewChunkedBody frames a body with chunked transfer coding, the only framing that can carry a completion trailer.
func NewIdentityBody ¶
func NewIdentityBody(w io.Writer) BodyWriter
NewIdentityBody writes a body whose length the head already declared. It cannot carry trailers: a short body is surfaced by the FIN arriving before the declared length is met.
type Completion ¶
type Completion string
Completion is how one direction of an exchange ended, spelled as the literal x-lk-completion trailer token. The empty value carries no information, so a sender that omits the field cannot thereby claim success; success is the body's own framing reaching its end and is never announced.
const ( CompletionUnknown Completion = "" CompletionTruncated Completion = "truncated" CompletionPeerGone Completion = "peer_gone" CompletionRefused Completion = "refused" CompletionInternal Completion = "internal" CompletionTimeout Completion = "timeout" CompletionCanceled Completion = "canceled" CompletionProtocol Completion = "protocol" )
func CompletionFromResetCode ¶
func CompletionFromResetCode(code livekit.AgentHttp_HttpStreamResetCode) Completion
CompletionFromResetCode is the inverse. HSR_ABORT carries no claim about whether the request was applied.
func (Completion) ResetCode ¶
func (c Completion) ResetCode() livekit.AgentHttp_HttpStreamResetCode
ResetCode is the QUIC reset code carrying this completion when it happened before any HTTP bytes flowed. Outcomes that can only arise mid-body have no code of their own and collapse to HSR_ABORT.
type CompletionError ¶
type CompletionError struct {
Completion Completion
Reason string
}
CompletionError is a terminal state other than success.
func CompletionFromTrailers ¶
func CompletionFromTrailers(t http.Header) *CompletionError
CompletionFromTrailers reports the outcome a peer announced, or nil when it announced none. No announcement, the body framing having reached its end, is success.
func (*CompletionError) Error ¶
func (e *CompletionError) Error() string
type SourceError ¶
type SourceError struct{ Err error }
SourceError reports that the body's source failed mid-copy. The stream is still intact, so the caller can close the body with a completion.
func (*SourceError) Error ¶
func (e *SourceError) Error() string
func (*SourceError) Unwrap ¶
func (e *SourceError) Unwrap() error