Fix nil pointer
This commit is contained in:
parent
8916f6b625
commit
d3cbde6ae2
13
http/cors.go
13
http/cors.go
|
@ -22,13 +22,18 @@ func wrapCORSHandler(h http.Handler, core *vault.Core) http.Handler {
|
|||
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||
corsConf := core.CORSConfig()
|
||||
|
||||
origin := req.Header.Get("Origin")
|
||||
requestMethod := req.Header.Get("Access-Control-Request-Method")
|
||||
|
||||
// If CORS is not enabled or if no Origin header is present (i.e. the request
|
||||
// is from the Vault CLI. A browser will always send an Origin header), then
|
||||
// just return a 204.
|
||||
if !corsConf.IsEnabled() || origin == "" {
|
||||
if !corsConf.IsEnabled() {
|
||||
h.ServeHTTP(w, req)
|
||||
return
|
||||
}
|
||||
|
||||
origin := req.Header.Get("Origin")
|
||||
requestMethod := req.Header.Get("Access-Control-Request-Method")
|
||||
|
||||
if origin == "" {
|
||||
h.ServeHTTP(w, req)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -517,7 +517,10 @@ func NewCore(conf *CoreConfig) (*Core, error) {
|
|||
}
|
||||
|
||||
// Load CORS config and provide a value for the core field.
|
||||
c.corsConfig = &CORSConfig{core: c}
|
||||
c.corsConfig = &CORSConfig{
|
||||
core: c,
|
||||
Enabled: new(uint32),
|
||||
}
|
||||
|
||||
phys := conf.Physical
|
||||
_, txnOK := conf.Physical.(physical.Transactional)
|
||||
|
|
|
@ -79,6 +79,11 @@ func (c *Core) loadCORSConfig(ctx context.Context) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if newConfig.Enabled == nil {
|
||||
newConfig.Enabled = new(uint32)
|
||||
}
|
||||
|
||||
newConfig.core = c
|
||||
|
||||
c.corsConfig = newConfig
|
||||
|
|
Loading…
Reference in New Issue