diff --git a/configuration/configuration.go b/configuration/configuration.go index 06aa4221..4ff339b8 100644 --- a/configuration/configuration.go +++ b/configuration/configuration.go @@ -24,6 +24,9 @@ type Configuration struct { // used to gate requests. Auth Auth `yaml:"auth"` + // LayerHandler specifies a middleware for serving image layers. + LayerHandler LayerHandler `yaml:"layerhandler"` + // Reporting is the configuration for error reporting Reporting Reporting `yaml:"reporting"` @@ -35,9 +38,6 @@ type Configuration struct { // Secret specifies the secret key which HMAC tokens are created with. Secret string `yaml:"secret"` - - // LayerHandler specifies a middleware for serving image layers. - LayerHandler LayerHandler `yaml:"layerhandler"` } `yaml:"http"` } @@ -290,7 +290,11 @@ func (layerHandler *LayerHandler) UnmarshalYAML(unmarshal func(interface{}) erro // MarshalYAML implements the yaml.Marshaler interface func (layerHandler LayerHandler) MarshalYAML() (interface{}, error) { if layerHandler.Parameters() == nil { - return layerHandler.Type(), nil + t := layerHandler.Type() + if t == "" { + return nil, nil + } + return t, nil } return map[string]Parameters(layerHandler), nil } diff --git a/registry/app.go b/registry/app.go index b757b9ab..72ac4f06 100644 --- a/registry/app.go +++ b/registry/app.go @@ -78,10 +78,10 @@ func NewApp(configuration configuration.Configuration) *App { app.accessController = accessController } - layerHandlerType := configuration.HTTP.LayerHandler.Type() + layerHandlerType := configuration.LayerHandler.Type() if layerHandlerType != "" { - lh, err := storage.GetLayerHandler(layerHandlerType, configuration.HTTP.LayerHandler.Parameters(), driver) + lh, err := storage.GetLayerHandler(layerHandlerType, configuration.LayerHandler.Parameters(), driver) if err != nil { panic(fmt.Sprintf("unable to configure layer handler (%s): %v", layerHandlerType, err)) } diff --git a/registry/layer.go b/registry/layer.go index 5d43a1ad..836df3b7 100644 --- a/registry/layer.go +++ b/registry/layer.go @@ -58,10 +58,12 @@ func (lh *layerHandler) GetLayer(w http.ResponseWriter, r *http.Request) { } defer layer.Close() - handler, err := lh.layerHandler.Resolve(layer) - if handler != nil { - handler.ServeHTTP(w, r) - return + if lh.layerHandler != nil { + handler, _ := lh.layerHandler.Resolve(layer) + if handler != nil { + handler.ServeHTTP(w, r) + return + } } http.ServeContent(w, r, layer.Digest().String(), layer.CreatedAt(), layer)