browser

package
v8.7.1-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package browser contains internal helpers that are only used for browser requests.

Index

Constants

View Source
const (
	// DefaultAllowedOrigin is the default origin string to use in CORS response headers.
	DefaultAllowedOrigin = "*"
)

Variables

View Source
var DefaultAllowedHeaders = strings.Join([]string{
	"Cache-Control",
	"Content-Type",
	"Content-Length",
	"Accept-Encoding",
	"X-LaunchDarkly-User-Agent",
	"X-LaunchDarkly-Payload-ID",
	"X-LaunchDarkly-Wrapper",
	events.EventSchemaHeader,
	events.TagsHeader,
}, ",")

DefaultAllowedHeaders is the default value of the CORS header Access-Control-Allow-Headers.

View Source
var Transparent1PixelImageData []byte = makePixelImageData() //nolint:gochecknoglobals

Transparent1PixelImageData is the response data for the fake-image endpoint that browsers can use to send events. It is exported for use in test code.

Functions

func SetCORSHeaders

func SetCORSHeaders(w http.ResponseWriter, origin string, extraAllowedHeaders []string)

SetCORSHeaders sets a standard set of CORS headers on an HTTP response. This is meant to be the same behavior that the LaunchDarkly service endpoints uses for client-side JS requests.

func WithCORSContext

func WithCORSContext(parent context.Context, cc CORSContext) context.Context

WithCORSContext returns a copy of the parent context with the specified CORSContext attached.

Types

type CORSContext

type CORSContext interface {
	AllowedOrigins() []string
	AllowedHeaders() []string
}

CORSContext represents a scope that has a specific set of allowed origins for CORS requests. This can be attached to a request context with WithCORSContext().

func GetCORSContext

func GetCORSContext(ctx context.Context) CORSContext

GetCORSContext returns the CORSContext that has been attached to this Context with WithCORSContext(), or nil if none.

Jump to

Keyboard shortcuts

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