corshandler

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: MIT Imports: 3 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

Index

Constants

View Source
const (
	CorsOptionMethod           string = "OPTIONS"
	CorsAllowOriginHeader      string = "Access-Control-Allow-Origin"
	CorsExposeHeadersHeader    string = "Access-Control-Expose-Headers"
	CorsMaxAgeHeader           string = "Access-Control-Max-Age"
	CorsAllowMethodsHeader     string = "Access-Control-Allow-Methods"
	CorsAllowHeadersHeader     string = "Access-Control-Allow-Headers"
	CorsAllowCredentialsHeader string = "Access-Control-Allow-Credentials"
	CorsRequestMethodHeader    string = "Access-Control-Request-Method"
	CorsRequestHeadersHeader   string = "Access-Control-Request-Headers"
	CorsOriginHeader           string = "Origin"
	CorsVaryHeader             string = "Vary"
	CorsOriginMatchAll         string = "*"
)

Variables

View Source
var (
	DefaultCorsOptionStatusCode = 200
	DefaultCorsMethods          = []string{"GET", "HEAD", "POST"}
	DefaultCorsHeaders          = []string{"Accept", "Accept-Language", "Content-Language", "Origin"}

	DefaultCors = Cors{
		AllowedMethods:   DefaultCorsMethods,
		AllowedHeaders:   DefaultCorsHeaders,
		AllowedOrigins:   []string{},
		OptionStatusCode: DefaultCorsOptionStatusCode,
	}
)

Functions

This section is empty.

Types

type Cors

type Cors struct {
	AllowedHeaders         []string
	AllowedMethods         []string
	AllowedOrigins         []string
	AllowedOriginValidator OriginValidator
	ExposedHeaders         []string
	MaxAge                 int
	IgnoreOptions          bool
	AllowCredentials       bool
	OptionStatusCode       int
	// contains filtered or unexported fields
}

func (*Cors) IsMatch

func (ch *Cors) IsMatch(needle string, haystack []string) bool

func (*Cors) IsOriginAllowed

func (ch *Cors) IsOriginAllowed(origin string) bool

func (*Cors) ServeHTTP

func (ch *Cors) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Cors) SetHandler

func (ch *Cors) SetHandler(h http.Handler)

type OriginValidator

type OriginValidator func(string) bool

OriginValidator takes an origin string and returns whether or not that origin is allowed.

Jump to

Keyboard shortcuts

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