wsmini

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 16 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

Overview

Package wsmini is the minimal RFC 6455 framing the Sprites exec channel needs, so the module takes no WebSocket dependency. It has a client (Dial) and a server side (Upgrade, for the Sprites fake): binary and text messages, fragmentation, ping/pong, close, masking rules and a message size limit. There is no compression, no extension and no subprotocol.

Index

Constants

View Source
const (
	OpText   = 0x1
	OpBinary = 0x2
	OpClose  = 0x8
	OpPing   = 0x9
	OpPong   = 0xA
)

Opcodes.

View Source
const DefaultMaxMessage = 16 << 20

DefaultMaxMessage bounds one reassembled message.

Variables

View Source
var (
	ErrTooBig   = errors.New("wsmini: message over the size limit")
	ErrProtocol = errors.New("wsmini: protocol error")
	// ErrClosed is returned by ReadMessage once the peer sent a close frame.
	ErrClosed = errors.New("wsmini: closed by peer")
)

Functions

This section is empty.

Types

type Conn

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

Conn is one WebSocket connection. ReadMessage must be called from one goroutine at a time; WriteMessage is safe for concurrent use.

func Dial

func Dial(ctx context.Context, rawURL string, o DialOptions) (*Conn, error)

Dial opens rawURL (http, https, ws or wss) and upgrades it. It never uses a proxy.

func Upgrade

func Upgrade(w http.ResponseWriter, r *http.Request, maxMessage int) (*Conn, error)

Upgrade is the server side: it checks the upgrade request, hijacks the connection and answers 101. A request that is not a valid upgrade is answered 400 and an error is returned.

func (*Conn) Abort

func (c *Conn) Abort() error

Abort closes the connection without a close frame (a dropped socket).

func (*Conn) Close

func (c *Conn) Close() error

Close sends a normal close frame (best effort) and closes the connection.

func (*Conn) Ping

func (c *Conn) Ping(p []byte) error

Ping sends a ping frame.

func (*Conn) ReadMessage

func (c *Conn) ReadMessage() (op int, payload []byte, err error)

ReadMessage returns the next text or binary message. Pings are answered and pongs dropped meanwhile. A close frame is answered and returns ErrClosed.

func (*Conn) RemoteAddr

func (c *Conn) RemoteAddr() net.Addr

RemoteAddr is the peer's address.

func (*Conn) SetReadDeadline

func (c *Conn) SetReadDeadline(t time.Time) error

SetReadDeadline passes through to the connection.

func (*Conn) WriteMessage

func (c *Conn) WriteMessage(op int, p []byte) error

WriteMessage sends p as one frame (masked on a client).

type DialError

type DialError struct{ Err error }

DialError: the connection could not be made, so no request byte was sent.

func (*DialError) Error

func (e *DialError) Error() string

func (*DialError) Unwrap

func (e *DialError) Unwrap() error

type DialOptions

type DialOptions struct {
	Header           http.Header
	MaxMessage       int
	HandshakeTimeout time.Duration
	TLS              *tls.Config
}

DialOptions: Header is added to the upgrade request; MaxMessage defaults to DefaultMaxMessage; HandshakeTimeout bounds the wait for the upgrade answer (default 30s); TLS is used for https and wss URLs (nil: the system roots).

type HandshakeError

type HandshakeError struct{ Err error }

HandshakeError: the upgrade request was written (the server may have acted on it), and the exchange then failed without an HTTP error status: a timeout, a network error, a bad answer.

func (*HandshakeError) Error

func (e *HandshakeError) Error() string

func (*HandshakeError) Unwrap

func (e *HandshakeError) Unwrap() error

type StatusError

type StatusError struct {
	Code int
	Body []byte // at most 64 KiB
}

StatusError: the server answered the upgrade request with an HTTP status other than 101.

func (*StatusError) Error

func (e *StatusError) Error() string

Jump to

Keyboard shortcuts

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