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.
type ProxyOption ¶
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).