browser

package
v9.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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",
	"X-LaunchDarkly-Instance-Id",
	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 AddVaryHeader

func AddVaryHeader(w http.ResponseWriter, fieldName string)

AddVaryHeader adds a field name to the response's Vary header, preserving any values already present and avoiding duplicates.

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.

Because Access-Control-Allow-Origin is derived from the request's Origin header, "Origin" is added to the response's Vary header so that shared caches do not serve one origin's response to another.

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