middleware

package
v8.4.1 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package middleware contains helpers for adding standard behavior like authentication and metrics to REST endpoints.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CORS

func CORS(next http.Handler) http.Handler

CORS is a middleware function that sets the appropriate CORS headers on a browser response (not counting Access-Control-Allow-Methods, which is set by gorilla/mux's CORS middleware based on the route handlers we've defined).

Also, if the HTTP method is OPTIONS, it will short-circuit the rest of the middleware chain so that the underlying handler is *not* called-- since an OPTIONS request should not do anything except set the CORS response headers. Therefore, we should always put the gorilla/mux CORS middleware before this one.

func Chain

func Chain(middlewares ...mux.MiddlewareFunc) mux.MiddlewareFunc

Chain combines a series of middleware functions that will be applied in the same order.

func ContextFromBase64

func ContextFromBase64(base64Context string) (ldcontext.Context, error)

ContextFromBase64 decodes a base64-encoded go-server-sdk evaluation context. If any decoding/unmarshaling errors occur, or the decoded context is invalid by the rules of the Go SDK, an error is returned.

func CountBrowserConns

func CountBrowserConns(handler http.Handler) http.Handler

CountBrowserConns is a middleware function that increments the total number of browser connections, and also increments the number of active browser connections until the handler ends.

func CountMobileConns

func CountMobileConns(handler http.Handler) http.Handler

CountMobileConns is a middleware function that increments the total number of mobile connections, and also increments the number of active mobile connections until the handler ends.

func CountServerConns

func CountServerConns(handler http.Handler) http.Handler

CountServerConns is a middleware function that increments the total number of server-side connections, and also increments the number of active server-side connections until the handler ends.

func PollingRequestCount

func PollingRequestCount(handler http.Handler) http.Handler

PollingRequestCount is a middleware function that increments the total number of server-side polling requests.

func RequestCount

func RequestCount(measure metrics.Measure) mux.MiddlewareFunc

RequestCount is a middleware function that increments the specified metric for each request.

func SelectEnvironmentByAuthorizationKey

func SelectEnvironmentByAuthorizationKey(sdkKind basictypes.SDKKind, envs RelayEnvironments) mux.MiddlewareFunc

SelectEnvironmentByAuthorizationKey creates a middleware function that attempts to authenticate the request using the appropriate kind of credential for the basictypes.SDKKind. If successful, it updates the request context so GetEnvContextInfo will return environment information. If not successful, it returns an error response.

func Streaming

func Streaming(next http.Handler) http.Handler

Streaming is a middleware function that sets the appropriate headers on a streaming response.

func WithEnvContextInfo

func WithEnvContextInfo(ctx context.Context, info EnvContextInfo) context.Context

WithEnvContextInfo returns a new Context with the EnvContextInfo added.

Types

type EnvContextInfo

type EnvContextInfo struct {
	// Env is an existing EnvContext object for the environment.
	Env relayenv.EnvContext

	// Credential is the SDK key, mobile key, or environment ID that was used in the request.
	Credential credential.SDKCredential
}

EnvContextInfo is data that we attach to the current HTTP request to indicate which environment it is related to.

func GetEnvContextInfo

func GetEnvContextInfo(ctx context.Context) EnvContextInfo

GetEnvContextInfo returns the EnvContextInfo that is attached to the specified Context (normally obtained from a request as request.Context()). It panics if there is none, since this context data is supposed to be injected by our middleware and our handlers cannot work without it.

type RelayEnvironments

type RelayEnvironments interface {
	// GetEnvironment returns the potentially filtered environment corresponding to scopedCred, or an error if no matching
	// environment could be found.
	GetEnvironment(scopedCred sdkauth.ScopedCredential) (env relayenv.EnvContext, err error)
	// IsNotReady should return true if the error returned by GetEnvironment represents the fact that Relay is not yet
	// fully configured.
	IsNotReady(error) bool
	// IsPayloadFilterNotFound should return true if the error returned by GetEnvironment represents the fact that
	// the credential was correct, but the payload filter was not found.
	IsPayloadFilterNotFound(error) bool
}

RelayEnvironments defines the methods for looking up environments. This is represented as an interface so that test code can mock that capability.

Jump to

Keyboard shortcuts

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