websockets

package
v0.0.0-...-84400b0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2022 License: MIT-0 Imports: 20 Imported by: 0

Documentation

Overview

Package websockets defines logic for the agent routing websocket connections.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Proxy

func Proxy(ctx context.Context, wrapped http.Handler, host, shimPath string, rewriteHost, enableWebsocketInjection bool, openWebsocketWrapper func(wrapped http.Handler, metricHandler *metrics.MetricHandler) http.Handler, metricHandler *metrics.MetricHandler) (http.Handler, error)

Proxy creates a reverse proxy that inserts websocket-shim code into all HTML responses. openWebsocketWrapper is a http.Handler wrapper function that is invoked on websocket open requests after the original targetURL of the request is restored. It must call the wrapped http.Handler with which it is created after it is finished processing the request.

func ShimBody

func ShimBody(shimPath string) (func(resp *http.Response) error, error)

ShimBody returns a function that injects code into a *http.Response Body

Types

type Connection

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

Connection implements a websocket client connection.

This wraps a websocket.Conn connection as defined by the gorilla/websocket library, and encapsulates it in an API that is a little more amenable to how the server side of our websocket shim is implemented.

func NewConnection

func NewConnection(ctx context.Context, targetURL string, header http.Header, errCallback func(err error)) (*Connection, error)

NewConnection creates and returns a new Connection.

func (*Connection) Close

func (conn *Connection) Close()

Close closes the websocket client connection.

func (*Connection) ReadServerMessages

func (conn *Connection) ReadServerMessages() ([]interface{}, error)

ReadServerMessages reads the next messages from the websocket server.

The returned error value is non-nill if the connection has been closed.

The returned []string value is nil if the error is non-nil, or if the method times out while waiting for a server message.

func (*Connection) SendClientMessage

func (conn *Connection) SendClientMessage(msg interface{}, injectionEnabled bool, injectedHeaders map[string]string) error

SendClientMessage sends the given message to the websocket server.

The returned error value is non-nill if the connection has been closed.

Jump to

Keyboard shortcuts

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