wsproxy

package
v0.2.12 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 11 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 Option

type Option func(*Proxy)

Option allows customization of the proxy.

func WithMethodParamOverride

func WithMethodParamOverride(param string) Option

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

func WithPingPong

func WithPingPong(b bool) Option

func WithRequestMutator

func WithRequestMutator(fn RequestMutatorFunc) Option

WithRequestMutator allows a custom RequestMutatorFunc to be supplied.

func WithTimeWait

func WithTimeWait(t int32) Option

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, 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