client

package
v0.2.21 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2021 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectViaProxy

func ConnectViaProxy(ctx context.Context, endpoint string, tlsClientConf *tls.Config, opts ...ConnectOption) (*grpc.ClientConn, error)

ConnectViaProxy establishes a gRPC client connection via a HTTP/2 proxy that handles endpoints behind HTTP/1.x proxies. Use the WithWebSocket() ConnectOption if you want to connect to a server via WebSocket. Otherwise, setting it to false will use a gRPC-Web "downgrade", as needed.

Using WebSocket will allow for both streaming and non-streaming gRPC requests, but is not adaptive. Using gRPC-Web "downgrades" will only allow for non-streaming gRPC requests, but will only downgrade if necessary. This method supports server-streaming requests, but only if there isn't a proxy in the middle that buffers chunked responses.

Types

type ConnectOption

type ConnectOption interface {
	// contains filtered or unexported methods
}

ConnectOption is an option that can be passed to the `ConnectViaProxy` method.

func DialOpts

func DialOpts(dialOpts ...grpc.DialOption) ConnectOption

DialOpts returns a connect option that applies the given gRPC dial options when connecting.

func ExtraH2ALPNs

func ExtraH2ALPNs(alpns ...string) ConnectOption

ExtraH2ALPNs returns a connection option that instructs the client to use the given ALPN names as HTTP/2 equivalent.

This option is ignored when `UseWebSocket(true)` is set.

func ForceDowngrade

func ForceDowngrade(force bool) ConnectOption

ForceDowngrade returns a connection option that instructs the client to always force gRPC-Web downgrade for gRPC requests. Client- or Bidi-streaming requests will not work. This option has no effect if websockets are being used.

func ForceHTTP2

func ForceHTTP2() ConnectOption

ForceHTTP2 returns a connection option that instructs the client to force using HTTP/2 even in the absence of ALPN. This is required for servers that only speak HTTP/2 (e.g., the vanilla gRPC server regardless of the language), but might break things if the server does not support HTTP/2 or expects HTTP/1. Generally, working with any kind of server requires a TLS connection that allows for ALPN.

This option is ignored when `UseWebSocket(true)` is set.

func UseWebSocket

func UseWebSocket(use bool) ConnectOption

UseWebSocket returns a connection option that instructs the client to use or not use a WebSocket connection with the server. The default is to not use a WebSocket connection.

Jump to

Keyboard shortcuts

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