Merge pull request #55 from BrianBland/layerhandler

Adds support for content redirects for layer downloads
This commit is contained in:
Stephen Day 2015-01-09 14:44:54 -08:00
commit 8f57e05016
2 changed files with 20 additions and 0 deletions

View file

@ -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
} }

View file

@ -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)
} }