Skip to content

Commit

Permalink
rename Allowed to Allow matching Field names (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
shaunrader authored and appleboy committed Apr 24, 2019
1 parent f9e1099 commit bd1331c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions cors.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ import (
type Config struct {
AllowAllOrigins bool

// AllowedOrigins is a list of origins a cross-domain request can be executed from.
// AllowOrigins is a list of origins a cross-domain request can be executed from.
// If the special "*" value is present in the list, all origins will be allowed.
// Default value is []
AllowOrigins []string

// AllowOriginFunc is a custom function to validate the origin. It take the origin
// as argument and returns true if allowed or false otherwise. If this option is
// set, the content of AllowedOrigins is ignored.
// set, the content of AllowOrigins is ignored.
AllowOriginFunc func(origin string) bool

// AllowedMethods is a list of methods the client is allowed to use with
// AllowMethods is a list of methods the client is allowed to use with
// cross-domain requests. Default value is simple methods (GET and POST)
AllowMethods []string

// AllowedHeaders is list of non simple headers the client is allowed to use with
// AllowHeaders is list of non simple headers the client is allowed to use with
// cross-domain requests.
AllowHeaders []string

Expand Down Expand Up @@ -97,7 +97,7 @@ func (c Config) validateAllowedSchemas(origin string) bool {
// Validate is check configuration of user defined.
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 AllowedOrigins is not needed")
return errors.New("conflict settings: all origins are allowed. AllowOriginFunc or AllowOrigins is not needed")
}
if !c.AllowAllOrigins && c.AllowOriginFunc == nil && len(c.AllowOrigins) == 0 {
return errors.New("conflict settings: all origins disabled")
Expand Down
8 changes: 4 additions & 4 deletions cors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func TestGeneratePreflightHeaders_AllowCredentials(t *testing.T) {
assert.Len(t, header, 2)
}

func TestGeneratePreflightHeaders_AllowedMethods(t *testing.T) {
func TestGeneratePreflightHeaders_AllowMethods(t *testing.T) {
header := generatePreflightHeaders(Config{
AllowMethods: []string{"GET ", "post", "PUT", " put "},
})
Expand All @@ -184,7 +184,7 @@ func TestGeneratePreflightHeaders_AllowedMethods(t *testing.T) {
assert.Len(t, header, 2)
}

func TestGeneratePreflightHeaders_AllowedHeaders(t *testing.T) {
func TestGeneratePreflightHeaders_AllowHeaders(t *testing.T) {
header := generatePreflightHeaders(Config{
AllowHeaders: []string{"X-user", "Content-Type"},
})
Expand Down Expand Up @@ -265,7 +265,7 @@ func TestValidateOrigin(t *testing.T) {
assert.True(t, cors.validateOrigin("chrome-extension://random-extension-id"))
}

func TestPassesAllowedOrigins(t *testing.T) {
func TestPassesAllowOrigins(t *testing.T) {
router := newTestRouter(Config{
AllowOrigins: []string{"http://google.com"},
AllowMethods: []string{" GeT ", "get", "post", "PUT ", "Head", "POST"},
Expand Down Expand Up @@ -331,7 +331,7 @@ func TestPassesAllowedOrigins(t *testing.T) {
assert.Empty(t, w.Header().Get("Access-Control-Max-Age"))
}

func TestPassesAllowedAllOrigins(t *testing.T) {
func TestPassesAllowAllOrigins(t *testing.T) {
router := newTestRouter(Config{
AllowAllOrigins: true,
AllowMethods: []string{" Patch ", "get", "post", "POST"},
Expand Down

0 comments on commit bd1331c

Please sign in to comment.