Serve blobs when a storage driver supports redirects but are disabled

Fixes issue where an error was returned instead of serving the blob

Signed-off-by: Brian Bland <brian.bland@docker.com>
This commit is contained in:
Brian Bland 2015-12-28 11:04:58 -08:00
parent e02a0b0399
commit cf487a7911

View file

@ -34,18 +34,22 @@ func (bs *blobServer) ServeBlob(ctx context.Context, w http.ResponseWriter, r *h
return err return err
} }
if bs.redirect {
redirectURL, err := bs.driver.URLFor(ctx, path, map[string]interface{}{"method": r.Method}) redirectURL, err := bs.driver.URLFor(ctx, path, map[string]interface{}{"method": r.Method})
switch err.(type) { switch err.(type) {
case nil: case nil:
if bs.redirect {
// Redirect to storage URL. // Redirect to storage URL.
http.Redirect(w, r, redirectURL, http.StatusTemporaryRedirect) http.Redirect(w, r, redirectURL, http.StatusTemporaryRedirect)
return err return err
}
case driver.ErrUnsupportedMethod: case driver.ErrUnsupportedMethod:
// Fallback to serving the content directly. // Fallback to serving the content directly.
default:
// Some unexpected error.
return err
}
}
br, err := newFileReader(ctx, bs.driver, path, desc.Size) br, err := newFileReader(ctx, bs.driver, path, desc.Size)
if err != nil { if err != nil {
return err return err
@ -71,8 +75,4 @@ func (bs *blobServer) ServeBlob(ctx context.Context, w http.ResponseWriter, r *h
http.ServeContent(w, r, desc.Digest.String(), time.Time{}, br) http.ServeContent(w, r, desc.Digest.String(), time.Time{}, br)
return nil return nil
}
// Some unexpected error.
return err
} }