...

Package wsproxy

import "github.com/tmc/grpc-websocket-proxy/wsproxy"
Overview
Index

Overview ▾

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

Variables

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.

var MethodOverrideParam = "method"

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.

var TokenCookieName = "token"

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

type Logger

Logger collects log messages.

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

type Option

Option allows customization of the proxy.

type Option func(*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

Proxy provides websocket transport upgrade to compatible endpoints.

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

func (*Proxy) ServeHTTP

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

type RequestMutatorFunc

RequestMutatorFunc can supply an alternate outgoing request.

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