ws

package
v1.37.39 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package ws is the one WebSocket upgrade zip performs. wsx.Upgrade (an untyped route) and a typed op answering zip.Socket both reach it.

Index

Constants

View Source
const Refusal = "this address speaks WebSocket: connect with an Upgrade: websocket request"

Refusal is the sentence a plain request to a WebSocket address is answered with, beside 426 and Upgrade: websocket (RFC 9110 §15.5.22).

View Source
const Version = "13"

Version is the protocol version a handshake must ask for (RFC 6455).

Variables

This section is empty.

Functions

func Admits

func Admits(rc *fasthttp.RequestCtx, origins []string) bool

Admits reports whether a request's Origin may open a connection: a request with no Origin (not a browser), one whose Origin names the request's own host, and one whose Origin is among origins, "*" being any.

func Is

func Is(rc *fasthttp.RequestCtx) bool

Is reports whether the request asks to become a WebSocket.

func Speaks

func Speaks(rc *fasthttp.RequestCtx) bool

Speaks reports whether a handshake's Sec-WebSocket-Version list names Version, read as the library reads it: comma-separated, case aside.

func Upgrade

func Upgrade(rc *fasthttp.RequestCtx, cfg Config, fn func(*Conn)) error

Upgrade answers 101 and runs fn on the connection once the handler that called it returns. The caller has already checked Is.

Types

type Config

type Config struct {
	// ReadBufferSize and WriteBufferSize size the connection's I/O buffers in
	// bytes; zero takes the library's default.
	ReadBufferSize  int
	WriteBufferSize int
	// Subprotocols are the protocols the server speaks, in its order of
	// preference; the first one the client also offers is selected.
	Subprotocols []string
	// EnableCompression negotiates per-message deflate when the client offers it.
	EnableCompression bool
	// CheckOrigin decides whether a request's Origin may open a connection.
	// Nil is the library's: an Origin, when there is one, must name the
	// request's own host.
	CheckOrigin func(ctx *fasthttp.RequestCtx) bool
}

Config configures an upgrade.

type Conn

type Conn = websocket.Conn

Conn is an upgraded connection.

Jump to

Keyboard shortcuts

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