wsproxy

package
v0.0.0-...-e5319fd Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package wsproxy implements a websocket proxy for grpc-gateway backed services

Index

Constants

This section is empty.

Variables

View Source
var MethodOverrideParam = "method"

MethodOverrideParam defines the special URL parameter that is translated into the subsequent proxied streaming http request's method.

Deprecated: it is preferable to use the Options parameters to WebSocketProxy to supply parameters.

View Source
var TokenCookieName = "token"

TokenCookieName defines the cookie name that is translated to an 'Authorization: Bearer' header in the streaming http request's headers.

Deprecated: it is preferable to use the Options parameters to WebSocketProxy to supply parameters.

Functions

func WebsocketProxy

func WebsocketProxy(h http.Handler, opts ...Option) http.Handler

WebsocketProxy attempts to expose the underlying handler as a bidi websocket stream with newline-delimited JSON as the content encoding.

The HTTP Authorization header is either populated from the Sec-Websocket-Protocol field or by a cookie. The cookie name is specified by the TokenCookieName value.

example:

Sec-Websocket-Protocol: Bearer, foobar

is converted to:

Authorization: Bearer foobar

Method can be overwritten with the MethodOverrideParam get parameter in the requested URL

Types

type Logger

type Logger interface {
	Warnln(...interface{})
	Debugln(...interface{})
}

Logger collects log messages.

type Option

type Option func(*Proxy)

Option allows customization of the proxy.

func WithForwardedHeaders

func WithForwardedHeaders(fn func(header string) bool) Option

WithForwardedHeaders allows controlling which headers are forwarded.

func WithLogger

func WithLogger(logger Logger) Option

WithLogger allows a custom FieldLogger to be supplied

func WithMaxRespBodyBufferSize

func WithMaxRespBodyBufferSize(nBytes int) Option

WithMaxRespBodyBufferSize allows specification of a custom size for the buffer used while reading the response body. By default, the bufio.Scanner used to read the response body sets the maximum token size to MaxScanTokenSize.

func WithMethodParamOverride

func WithMethodParamOverride(param string) Option

WithMethodParamOverride allows specification of the special http parameter that is used in the proxied streaming request.

func WithPingControl

func WithPingControl(interval time.Duration) Option

WithPingControl allows specification of ping pong control. The interval parameter specifies the pingInterval between pings. The allowed wait time for a pong response is (pingInterval * 10) / 9.

func WithRequestMutator

func WithRequestMutator(fn RequestMutatorFunc) Option

WithRequestMutator allows a custom RequestMutatorFunc to be supplied.

func WithTokenCookieName

func WithTokenCookieName(param string) Option

WithTokenCookieName allows specification of the cookie that is supplied as an upstream 'Authorization: Bearer' http header.

type Proxy

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

Proxy provides websocket transport upgrade to compatible endpoints.

func (*Proxy) ServeHTTP

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

type RequestMutatorFunc

type RequestMutatorFunc func(incoming *http.Request, outgoing *http.Request) *http.Request

RequestMutatorFunc can supply an alternate outgoing request.

Jump to

Keyboard shortcuts

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