ws

package
v2.7.8 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 11 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 ws wraps `github.com/coder/websocket` (EdgeFetch's sole external Go dependency) behind a minimal, hardened outbound WebSocket control-plane client.

Transport Hardening

  • Forces HTTP/1.1 ALPN (`NextProtos: ["http/1.1"]`) required for RFC 6455 `Upgrade: websocket` handshakes.
  • Restricts TLS key exchange to classic ECDHE curves (ClassicTLSConfig) to avoid 1.2 KiB post-quantum `X25519MLKEM768` ClientHello middlebox drops on residential ISP routers.
  • Ignores ambient `HTTP_PROXY` / `HTTPS_PROXY` variables (`Proxy: nil`) and refuses HTTP redirects so `Authorization: Bearer <agent_token>` headers can never leak to third-party hosts.
  • Disables RFC 7692 `permessage-deflate` compression (`CompressionDisabled`) to prevent sliding-window RAM overhead and decompression-bomb amplification, with a strict 1 MiB inbound frame cap.

Index

Constants

View Source
const (
	MaxMessageBytes = 1 << 20 // 1 MiB ceiling on Hub control-plane frames

)

Variables

This section is empty.

Functions

func ClassicTLSConfig

func ClassicTLSConfig() *tls.Config

ClassicTLSConfig pins ECDHE curves (`X25519`, `P-256`, `P-384`) so post-quantum hybrid key shares do not push TLS `ClientHello` packets past PPPoE, WireGuard, or VM NAT bridge MTU limits.

Types

type Conn

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

Conn wraps an active outbound client WebSocket connection.

func Dial

func Dial(ctx context.Context, rawURL, userAgent string, extraHeaders map[string]string) (*Conn, error)

Dial opens an outbound HTTP/1.1 WebSocket connection (`wss://`, `https://`, `ws://`, or `http://`).

func DialWithOptions

func DialWithOptions(ctx context.Context, rawURL, userAgent string, extraHeaders map[string]string, opts DialOptions) (*Conn, error)

DialWithOptions opens an outbound WebSocket connection with optional TLS root CA overrides for local TLS tests.

func (*Conn) CloseCleanly

func (c *Conn) CloseCleanly() error

CloseCleanly sends an RFC 6455 `1000` normal closure frame and closes the underlying connection.

func (*Conn) CloseNow

func (c *Conn) CloseNow() error

CloseNow closes the underlying TCP/TLS socket immediately without waiting for a close handshake.

func (*Conn) ReadText

func (c *Conn) ReadText(readTimeout time.Duration) (string, error)

ReadText reads the next message with `readTimeout`, mapping any peer WebSocket close frame cleanly to `io.EOF`.

func (*Conn) SetReadLimit

func (c *Conn) SetReadLimit(limit int64)

SetReadLimit overrides the maximum incoming WebSocket message size in bytes.

func (*Conn) WriteText

func (c *Conn) WriteText(s string) error

WriteText sends a UTF-8 text message (preserving Cloudflare's Hibernating WebSocket `"ping"` -> `"pong"` auto-response).

type DialOptions

type DialOptions struct {
	TLSConfig *tls.Config
}

DialOptions allows tests to supply custom TLS root CAs while preserving all transport hardening invariants.

Jump to

Keyboard shortcuts

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