forked from TrueCloudLab/distribution
Merge pull request #55 from BrianBland/layerhandler
Adds support for content redirects for layer downloads
This commit is contained in:
commit
8f57e05016
2 changed files with 20 additions and 0 deletions
12
docs/app.go
12
docs/app.go
|
@ -31,6 +31,8 @@ type App struct {
|
||||||
|
|
||||||
tokenProvider tokenProvider
|
tokenProvider tokenProvider
|
||||||
|
|
||||||
|
layerHandler storage.LayerHandler
|
||||||
|
|
||||||
accessController auth.AccessController
|
accessController auth.AccessController
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,6 +78,16 @@ func NewApp(configuration configuration.Configuration) *App {
|
||||||
app.accessController = accessController
|
app.accessController = accessController
|
||||||
}
|
}
|
||||||
|
|
||||||
|
layerHandlerType := configuration.LayerHandler.Type()
|
||||||
|
|
||||||
|
if layerHandlerType != "" {
|
||||||
|
lh, err := storage.GetLayerHandler(layerHandlerType, configuration.LayerHandler.Parameters(), driver)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Sprintf("unable to configure layer handler (%s): %v", layerHandlerType, err))
|
||||||
|
}
|
||||||
|
app.layerHandler = lh
|
||||||
|
}
|
||||||
|
|
||||||
return app
|
return app
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,5 +58,13 @@ func (lh *layerHandler) GetLayer(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
defer layer.Close()
|
defer layer.Close()
|
||||||
|
|
||||||
|
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)
|
http.ServeContent(w, r, layer.Digest().String(), layer.CreatedAt(), layer)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue