ws

package
v0.0.0-...-1aa08c1 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package ws provides a WebSocket proxy with support for bidirectional streaming on DRPC servers.

The proxy is intended to enhance the functionality provided by the standard DRPC packages by allowing bidirectional streaming using websockets.

// Create a new proxy instance
proxy, _ := New(EnableCompression())

// Obtain the original HTTP handler from your DRPC server mux
handler := drpchttp.New(srv.mux)

// Get a new handler enhanced with the proxy functionality
enhanced := proxy.Wrap(srv.mux, drpchttp.New(srv.mux))

// Use the enhanced handler as usual
return http.ListenAndServe(":9090", enhanced)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Proxy

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

Proxy provides support for bidirectional DRPC streaming via websockets.

func New

func New(opts ...ProxyOption) (*Proxy, error)

New returns a new WebSocket proxy instance.

func (*Proxy) ServeHTTP

func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP handles incoming HTTP requests.

func (*Proxy) Wrap

func (p *Proxy) Wrap(handler drpc.Handler, fallback http.Handler) http.Handler

Wrap the provided DRPC handler using `fallback` as handler for HTTP clients not requesting a WebSocket protocol connection upgrade.

type ProxyOption

type ProxyOption func(p *Proxy) error

ProxyOption provides functional-style configuration settings for a proxy instance.

func CheckOrigin

func CheckOrigin(f func(*http.Request) bool) ProxyOption

CheckOrigin should return true if the request Origin header is acceptable. If no setting is provided a safe default is used: return false if the Origin request header is present and the origin host is not equal to request Host header. A CheckOrigin function should carefully validate the request origin to prevent cross-site request forgery.

func EnableCompression

func EnableCompression() ProxyOption

EnableCompression specify if the server should attempt to negotiate per message compression (RFC 7692). Setting this value to true does not guarantee that compression will be supported. Currently, only "no context takeover" modes are supported.

func HandshakeTimeout

func HandshakeTimeout(timeout time.Duration) ProxyOption

HandshakeTimeout specifies the duration for the handshake to complete.

func SubProtocols

func SubProtocols(list []string) ProxyOption

SubProtocols specifies the server's supported protocols in order of preference. If no value is provided, the server negotiates a sub-protocol by selecting the first match in this list with a protocol requested by the client. If there's no match, then no protocol is negotiated (the Sec-Websocket-Protocol header is not included in the handshake response).

Jump to

Keyboard shortcuts

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