Documentation
¶
Overview ¶
Package websocket reads the frames of a WebSocket connection (RFC 6455 §5), so that the engine's reverse proxy can inspect a client's messages before it forwards them (#276).
A Reader reads what a client sends: every frame masked, no extension (the proxy removes Sec-WebSocket-Extensions from the handshake, so permessage-deflate is never negotiated and a frame with an RSV bit is an error), control frames whole and at most 125 bytes, interleaved with the fragments of a message. It returns each frame as it came, raw, so that it can be forwarded unchanged, with the payload unmasked. A Tracker follows what a server sends, to find the boundaries between its frames.
Index ¶
Constants ¶
const ( OpContinuation = 0x0 OpText = 0x1 OpBinary = 0x2 OpClose = 0x8 OpPing = 0x9 OpPong = 0xa )
Opcodes (RFC 6455 §5.2).
const ( CloseProtocolError = 1002 CloseUnsupportedData = 1003 CloseInvalidPayload = 1007 ClosePolicyViolation = 1008 CloseMessageTooBig = 1009 )
Close codes (RFC 6455 §7.4.1).
Variables ¶
This section is empty.
Functions ¶
func CloseFrame ¶
CloseFrame returns a close frame with code and reason (at most 123 bytes), masked with key when key isn't nil (a client's frame), unmasked otherwise (a server's).
Types ¶
type Frame ¶
type Frame struct {
Fin bool
Opcode byte
// Raw is the frame as it came: header, masking key and masked payload.
Raw []byte
// Payload is the unmasked payload, or as much of it as fits the
// Reader's limit for its message (Truncated).
Payload []byte
// Truncated: the message is over the limit, and Raw and Payload end
// where it was reached. The rest of the frame is still to be read, raw,
// with ReadRest.
Truncated bool
}
Frame is one frame a client sent.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader reads a client's frames.
func NewReader ¶
NewReader returns a Reader of the frames on r, keeping at most limit payload bytes of each data message (the frames past it are returned raw, with Truncated set).
func (*Reader) Next ¶
Next reads the next frame. It returns an *Error for a frame that breaks the protocol, io.EOF when the connection ends between frames, and io.ErrUnexpectedEOF when it ends inside one.
type Tracker ¶
type Tracker struct {
// contains filtered or unexported fields
}
Tracker follows a server's frames as their bytes pass, to tell when the stream is between two frames, where a frame of the proxy's own can go.
func (*Tracker) AtBoundary ¶
AtBoundary reports whether the bytes seen so far end with a whole frame.