wstunnel

package
v17.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TunnelWebSocketProtocol is a subprotocol that allows client and server recognize each other.
	// See https://datatracker.ietf.org/doc/html/rfc6455#section-11.3.4
	TunnelWebSocketProtocol = "ws-tunnel"
)

Variables

This section is empty.

Functions

func DialerForGRPC

func DialerForGRPC(readLimit int64, dialOpts *websocket.DialOptions) func(context.Context, string) (net.Conn, error)

DialerForGRPC can be used as an adapter between "ws"/"wss" URL scheme that the websocket library wants and gRPC target naming scheme.

Types

type HTTPHandler

type HTTPHandler struct {
	Ctx           context.Context
	ServerName    string
	AcceptOptions websocket.AcceptOptions
	Sink          chan<- net.Conn
	// ReadLimit. Optional. See websocket.Conn.SetReadLimit().
	ReadLimit int64
}

func (*HTTPHandler) ServeHTTP

func (h *HTTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Listener

type Listener interface {
	net.Listener
	// Shutdown gracefully shuts down the server without interrupting any
	// active connections. See http.Server.Shutdown().
	Shutdown(context.Context) error
}

type ListenerWrapper

type ListenerWrapper struct {
	AcceptOptions websocket.AcceptOptions
	// ReadLimit. Optional. See websocket.Conn.SetReadLimit().
	ReadLimit  int64
	ServerName string

	ReadTimeout       time.Duration
	ReadHeaderTimeout time.Duration
	WriteTimeout      time.Duration
	IdleTimeout       time.Duration
	MaxHeaderBytes    int
	ConnState         func(net.Conn, http.ConnState)
	ErrorLog          *log.Logger
	BaseContext       func(net.Listener) context.Context
	ConnContext       func(ctx context.Context, c net.Conn) context.Context
}

ListenerWrapper does two things:

  • HTTP/1.1 connections are expected to contain WebSocket upgrade request. Such connections are turned into TCP streams and returned from Accept(). This mode can be used for tunneling an HTTP/2 protocol via a WebSocket connection.
  • HTTP/2 connections are returned from Accept() as is.

There are two modes of operation - with and without TLS. Whether connection is HTTP/1.1 or HTTP/2 is determined by looking at: - TLS: what protocol was negotiated via ALPN. h2 means HTTP/2, everything else is considered HTTP/1.1. - Cleartext: if byte stream contains the standard h2 client preface then it's an HTTP/2 connection, HTTP/1.1 otherwise. See https://httpwg.org/specs/rfc9113.html#preface. See https://www.rfc-editor.org/rfc/rfc7301.html.

func (*ListenerWrapper) Wrap

func (w *ListenerWrapper) Wrap(source net.Listener, isTLS bool) Listener

Jump to

Keyboard shortcuts

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