summaryrefslogtreecommitdiff
path: root/vendor/github.com/gin-contrib/cors/cors.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/gin-contrib/cors/cors.go')
-rw-r--r--vendor/github.com/gin-contrib/cors/cors.go15
1 files changed, 6 insertions, 9 deletions
diff --git a/vendor/github.com/gin-contrib/cors/cors.go b/vendor/github.com/gin-contrib/cors/cors.go
index d6d06de03..f0e230ae4 100644
--- a/vendor/github.com/gin-contrib/cors/cors.go
+++ b/vendor/github.com/gin-contrib/cors/cors.go
@@ -23,7 +23,7 @@ type Config struct {
AllowOriginFunc func(origin string) bool
// AllowMethods is a list of methods the client is allowed to use with
- // cross-domain requests. Default value is simple methods (GET and POST)
+ // cross-domain requests. Default value is simple methods (GET, POST, PUT, PATCH, DELETE, HEAD, and OPTIONS)
AllowMethods []string
// AllowHeaders is list of non simple headers the client is allowed to use with
@@ -34,11 +34,11 @@ type Config struct {
// cookies, HTTP authentication or client side SSL certificates.
AllowCredentials bool
- // ExposedHeaders indicates which headers are safe to expose to the API of a CORS
+ // ExposeHeaders indicates which headers are safe to expose to the API of a CORS
// API specification
ExposeHeaders []string
- // MaxAge indicates how long (in seconds) the results of a preflight request
+ // MaxAge indicates how long (with second-precision) the results of a preflight request
// can be cached
MaxAge time.Duration
@@ -95,7 +95,7 @@ func (c Config) validateAllowedSchemas(origin string) bool {
}
// Validate is check configuration of user defined.
-func (c *Config) Validate() error {
+func (c Config) Validate() error {
if c.AllowAllOrigins && (c.AllowOriginFunc != nil || len(c.AllowOrigins) > 0) {
return errors.New("conflict settings: all origins are allowed. AllowOriginFunc or AllowOrigins is not needed")
}
@@ -103,10 +103,7 @@ func (c *Config) Validate() error {
return errors.New("conflict settings: all origins disabled")
}
for _, origin := range c.AllowOrigins {
- if origin == "*" {
- c.AllowAllOrigins = true
- return nil
- } else if !strings.Contains(origin, "*") && !c.validateAllowedSchemas(origin) {
+ if !strings.Contains(origin, "*") && !c.validateAllowedSchemas(origin) {
return errors.New("bad origin: origins must contain '*' or include " + strings.Join(c.getAllowedSchemas(), ","))
}
}
@@ -148,7 +145,7 @@ func (c Config) parseWildcardRules() [][]string {
// DefaultConfig returns a generic default configuration mapped to localhost.
func DefaultConfig() Config {
return Config{
- AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "HEAD"},
+ AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"},
AllowHeaders: []string{"Origin", "Content-Length", "Content-Type"},
AllowCredentials: false,
MaxAge: 12 * time.Hour,