Documentation
¶
Overview ¶
Package websocket is the Engine.IO WebSocket transport, built on gobwas/ws.
The codec (Encode, Decode) handles the contents of one WebSocket data message as an Engine.IO v4 packet; message.go handles RFC 6455 headers, masking, fragmentation, control frames and bounded reads. Engine.IO PING/PONG packets are distinct from WebSocket ping/pong control frames.
permessage-deflate is not negotiated: the handshake never offers or accepts an extension.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidPacket indicates malformed data or an unrepresentable packet. ErrInvalidPacket = errors.New("websocket: invalid packet") // ErrTooLarge indicates message contents exceed the caller's byte limit. ErrTooLarge = errors.New("websocket: packet too large") // ErrInvalidLimit indicates a nonpositive message size limit. ErrInvalidLimit = errors.New("websocket: message size limit must be positive") )
var Default = &Transport{}
Default is default transport.
var ErrMessageType = errors.New("websocket: only text and binary messages are supported")
ErrMessageType is returned by a write of anything but a text or binary message.
var ErrNotHijacker = errors.New("websocket: response writer does not support hijacking")
ErrNotHijacker is returned by Accept when the response writer does not implement http.Hijacker (HTTP/2, or a wrapper that hides the interface). The server answers HTTP 501.
Functions ¶
func Encode ¶
Encode returns the WebSocket data message type and contents for p. When supportsBinary is false, binary data uses a text message with a 'b' prefix and canonical padded base64, as in the JS parser. Otherwise binary data is sent unchanged, including empty data. Text data gets a type byte and may contain the polling record separator: WebSocket messages already provide boundaries. maxBytes must be positive and limits encoded contents, excluding WebSocket headers. The result owns its bytes; errors never return partial contents.
Types ¶
type HandshakeError ¶
type HandshakeError struct {
Err error
}
HandshakeError is the error of a handshake the server rejected. Accept has already answered the request, so the caller must not write to the response.
func (HandshakeError) Error ¶
func (e HandshakeError) Error() string
func (HandshakeError) Unwrap ¶
func (e HandshakeError) Unwrap() error
type Packet ¶
Packet contains data without an Engine.IO type prefix. Binary packets must have type MESSAGE; the v4 binary encoding cannot represent any other type.
func Decode ¶
Decode decodes one complete WebSocket data message. Raw binary messages are MESSAGE packets with no Engine.IO type byte. Text messages beginning with 'b' decode to binary MESSAGE packets, matching the JS parser's base64 fallback. Text otherwise requires a type byte in '0'..'6' and valid UTF-8 data. maxBytes must be positive and counts encoded contents, not WebSocket headers. Callers must also limit reads before buffering; this function cannot bound their allocations. Results own their data; errors return the zero Packet. As in the staged polling codec, base64 must be canonical and contain no whitespace.
type Transport ¶
type Transport struct {
// ReadBufferSize and WriteBufferSize are I/O buffer sizes in bytes. A zero
// ReadBufferSize reads the socket unbuffered after the handshake, which keeps
// no memory per idle connection. A zero WriteBufferSize sizes the buffer of
// each message to hold it in one frame.
ReadBufferSize int
WriteBufferSize int
// MaxPayload limits one message, in wire bytes (frames of a fragmented
// message together), on both sides. A larger message ends the connection with
// close status 1009. Zero means payload.DefaultMaxPayload.
MaxPayload int
Subprotocols []string
TLSClientConfig *tls.Config
HandshakeTimeout time.Duration
// Proxy returns the HTTP proxy for a dial, or nil for none. Only http proxy
// URLs are supported, through CONNECT; any other scheme fails the dial.
Proxy func(*http.Request) (*url.URL, error)
NetDial func(network, addr string) (net.Conn, error)
CheckOrigin func(r *http.Request) bool
}
Transport is websocket transport. The upgrade hijacks an HTTP/1.1 connection, and permessage-deflate is never negotiated.