-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update CORS middleware and make it configurable
- Loading branch information
David Christofas
committed
Oct 22, 2021
1 parent
c370276
commit 5df22a1
Showing
28 changed files
with
359 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package cors | ||
|
||
import ( | ||
"github.com/owncloud/ocis/ocis-pkg/log" | ||
) | ||
|
||
// Option defines a single option function. | ||
type Option func(o *Options) | ||
|
||
// Options defines the available options for this package. | ||
type Options struct { | ||
// Logger to use for logging, must be set | ||
Logger log.Logger | ||
// AllowedOrigins represents the allowed CORS origins | ||
AllowedOrigins []string | ||
// AllowedMethods represents the allowed CORS methods | ||
AllowedMethods []string | ||
// AllowedHeaders represents the allowed CORS headers | ||
AllowedHeaders []string | ||
// AllowCredentials represents the AllowCredentials CORS option | ||
AllowCredentials bool | ||
} | ||
|
||
// newAccountOptions initializes the available default options. | ||
func NewOptions(opts ...Option) Options { | ||
opt := Options{} | ||
|
||
for _, o := range opts { | ||
o(&opt) | ||
} | ||
|
||
return opt | ||
} | ||
|
||
// Logger provides a function to set the logger option. | ||
func Logger(l log.Logger) Option { | ||
return func(o *Options) { | ||
o.Logger = l | ||
} | ||
} | ||
|
||
// AllowedOrigins provides a function to set the AllowedOrigins option. | ||
func AllowedOrigins(origins []string) Option { | ||
return func(o *Options) { | ||
o.AllowedOrigins = origins | ||
} | ||
} | ||
|
||
// AllowedMethods provides a function to set the AllowedMethods option. | ||
func AllowedMethods(methods []string) Option { | ||
return func(o *Options) { | ||
o.AllowedMethods = methods | ||
} | ||
} | ||
|
||
// AllowedHeaders provides a function to set the AllowedHeaders option. | ||
func AllowedHeaders(headers []string) Option { | ||
return func(o *Options) { | ||
o.AllowedHeaders = headers | ||
} | ||
} | ||
|
||
// AlloweCredentials provides a function to set the AllowCredentials option. | ||
func AllowCredentials(allow bool) Option { | ||
return func(o *Options) { | ||
o.AllowCredentials = allow | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.