corshandler

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: MIT Imports: 3 Imported by: 0

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