diff options
Diffstat (limited to 'plugins/headers')
-rw-r--r-- | plugins/headers/config.go | 14 | ||||
-rw-r--r-- | plugins/headers/plugin.go | 7 |
2 files changed, 14 insertions, 7 deletions
diff --git a/plugins/headers/config.go b/plugins/headers/config.go index 8d4e29c2..688b4764 100644 --- a/plugins/headers/config.go +++ b/plugins/headers/config.go @@ -2,7 +2,7 @@ package headers // Config declares headers service configuration. type Config struct { - Headers struct { + Headers *struct { // CORS settings. CORS *CORSConfig @@ -17,20 +17,20 @@ type Config struct { // CORSConfig headers configuration. type CORSConfig struct { // AllowedOrigin: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin - AllowedOrigin string + AllowedOrigin string `mapstructure:"allowed_origin"` // AllowedHeaders: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers - AllowedHeaders string + AllowedHeaders string `mapstructure:"allowed_headers"` // AllowedMethods: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Methods - AllowedMethods string + AllowedMethods string `mapstructure:"allowed_methods"` // AllowCredentials https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Credentials - AllowCredentials *bool + AllowCredentials *bool `mapstructure:"allow_credentials"` // ExposeHeaders: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Expose-Headers - ExposedHeaders string + ExposedHeaders string `mapstructure:"exposed_headers"` // MaxAge of CORS headers in seconds/ - MaxAge int + MaxAge int `mapstructure:"max_age"` } diff --git a/plugins/headers/plugin.go b/plugins/headers/plugin.go index 3f25a1ed..a5ee702f 100644 --- a/plugins/headers/plugin.go +++ b/plugins/headers/plugin.go @@ -22,11 +22,18 @@ type Plugin struct { // misconfiguration. Services must not be used without proper configuration pushed first. func (s *Plugin) Init(cfg config.Configurer) error { const op = errors.Op("headers_plugin_init") + if !cfg.Has(RootPluginName) { + return errors.E(op, errors.Disabled) + } err := cfg.UnmarshalKey(RootPluginName, &s.cfg) if err != nil { return errors.E(op, errors.Disabled, err) } + if s.cfg.Headers == nil { + return errors.E(op, errors.Disabled) + } + return nil } |