Adds support for content redirects for layer downloads

Includes a delegate implementation which redirects to the URL generated
by the storagedriver, and a cloudfront implementation.
Satisfies proposal #49
This commit is contained in:
Brian Bland 2015-01-08 16:55:40 -08:00
parent c02f1a5507
commit b11d549fd0
2 changed files with 18 additions and 0 deletions

View file

@ -31,6 +31,8 @@ type App struct {
tokenProvider tokenProvider
layerHandler storage.LayerHandler
accessController auth.AccessController
}
@ -76,6 +78,16 @@ func NewApp(configuration configuration.Configuration) *App {
app.accessController = accessController
}
layerHandlerType := configuration.HTTP.LayerHandler.Type()
if layerHandlerType != "" {
lh, err := storage.GetLayerHandler(layerHandlerType, configuration.HTTP.LayerHandler.Parameters(), driver)
if err != nil {
panic(fmt.Sprintf("unable to configure layer handler (%s): %v", layerHandlerType, err))
}
app.layerHandler = lh
}
return app
}

View file

@ -58,5 +58,11 @@ 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
}
http.ServeContent(w, r, layer.Digest().String(), layer.CreatedAt(), layer)
}