cors

package
v3.0.24 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	XMLNS     string   `xml:"xmlns,attr,omitempty"`
	XMLName   xml.Name `xml:"CORSConfiguration"`
	CORSRules []Rule   `xml:"CORSRule"`
}

Config is the container for a CORS configuration for a bucket.

func ParseBucketCorsConfig

func ParseBucketCorsConfig(reader io.Reader) (*Config, error)

ParseBucketCorsConfig parses a CORS configuration in XML from an io.Reader.

func (Config) ToXML

func (c Config) ToXML() ([]byte, error)

ToXML marshals the CORS configuration to XML.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks the CORS configuration is valid. This has been implemented to return errors that can be transformed to match the S3 API externally, while being slightly more informative internally using wrapping. Validate copies S3 behavior, and validates one rule at a time, erroring on the first invalid one found.

type ErrAllowedHeaderWildcards

type ErrAllowedHeaderWildcards struct {
	Header string
}

ErrAllowedHeaderWildcards is returned when more than one wildcard is found in an AllowedHeader.

func (ErrAllowedHeaderWildcards) Error

type ErrAllowedOriginWildcards

type ErrAllowedOriginWildcards struct {
	Origin string
}

ErrAllowedOriginWildcards is returned when more than one wildcard is found in an AllowedOrigin.

func (ErrAllowedOriginWildcards) Error

type ErrInvalidMethod

type ErrInvalidMethod struct {
	Method string
}

ErrInvalidMethod is returned when an unsupported HTTP method is found in a CORS config.

func (ErrInvalidMethod) Error

func (e ErrInvalidMethod) Error() string

type ErrMalformedXML

type ErrMalformedXML struct{}

ErrMalformedXML is returned when the XML provided is not well-formed

func (ErrMalformedXML) Error

func (e ErrMalformedXML) Error() string

type ErrTooManyRules

type ErrTooManyRules struct{}

ErrTooManyRules is returned when the number of CORS rules exceeds the allowed limit.

func (ErrTooManyRules) Error

func (e ErrTooManyRules) Error() string

type Rule

type Rule struct {
	AllowedHeader []string `xml:"AllowedHeader,omitempty"`
	AllowedMethod []string `xml:"AllowedMethod,omitempty"`
	AllowedOrigin []string `xml:"AllowedOrigin,omitempty"`
	ExposeHeader  []string `xml:"ExposeHeader,omitempty"`
	ID            string   `xml:"ID,omitempty"`
	MaxAgeSeconds int      `xml:"MaxAgeSeconds,omitempty"`
}

Rule is a single rule in a CORS configuration.

func (*Rule) FilterAllowedHeaders

func (c *Rule) FilterAllowedHeaders(headers []string) ([]string, bool)

FilterAllowedHeaders returns the headers that are allowed by the rule, and a boolean indicating if all headers are allowed.

func (*Rule) HasAllowedMethod

func (c *Rule) HasAllowedMethod(method string) bool

HasAllowedMethod returns true if the given method is contained in the CORS rule.

func (*Rule) HasAllowedOrigin

func (c *Rule) HasAllowedOrigin(origin string) bool

HasAllowedOrigin returns true if the given origin is allowed by the CORS rule

Jump to

Keyboard shortcuts

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