forked from TrueCloudLab/distribution
Merge pull request #1303 from BrianBland/fixDisabledStorageRedirects
Serve blobs when a storage driver supports redirects but are disabled
This commit is contained in:
commit
05d1abbcb4
1 changed files with 33 additions and 33 deletions
|
@ -34,45 +34,45 @@ func (bs *blobServer) ServeBlob(ctx context.Context, w http.ResponseWriter, r *h
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
redirectURL, err := bs.driver.URLFor(ctx, path, map[string]interface{}{"method": r.Method})
|
if bs.redirect {
|
||||||
|
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.
|
||||||
br, err := newFileReader(ctx, bs.driver, path, desc.Size)
|
default:
|
||||||
if err != nil {
|
// Some unexpected error.
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer br.Close()
|
|
||||||
|
|
||||||
w.Header().Set("ETag", fmt.Sprintf(`"%s"`, desc.Digest)) // If-None-Match handled by ServeContent
|
|
||||||
w.Header().Set("Cache-Control", fmt.Sprintf("max-age=%.f", blobCacheControlMaxAge.Seconds()))
|
|
||||||
|
|
||||||
if w.Header().Get("Docker-Content-Digest") == "" {
|
|
||||||
w.Header().Set("Docker-Content-Digest", desc.Digest.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
if w.Header().Get("Content-Type") == "" {
|
|
||||||
// Set the content type if not already set.
|
|
||||||
w.Header().Set("Content-Type", desc.MediaType)
|
|
||||||
}
|
|
||||||
|
|
||||||
if w.Header().Get("Content-Length") == "" {
|
|
||||||
// Set the content length if not already set.
|
|
||||||
w.Header().Set("Content-Length", fmt.Sprint(desc.Size))
|
|
||||||
}
|
|
||||||
|
|
||||||
http.ServeContent(w, r, desc.Digest.String(), time.Time{}, br)
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Some unexpected error.
|
br, err := newFileReader(ctx, bs.driver, path, desc.Size)
|
||||||
return err
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer br.Close()
|
||||||
|
|
||||||
|
w.Header().Set("ETag", fmt.Sprintf(`"%s"`, desc.Digest)) // If-None-Match handled by ServeContent
|
||||||
|
w.Header().Set("Cache-Control", fmt.Sprintf("max-age=%.f", blobCacheControlMaxAge.Seconds()))
|
||||||
|
|
||||||
|
if w.Header().Get("Docker-Content-Digest") == "" {
|
||||||
|
w.Header().Set("Docker-Content-Digest", desc.Digest.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
if w.Header().Get("Content-Type") == "" {
|
||||||
|
// Set the content type if not already set.
|
||||||
|
w.Header().Set("Content-Type", desc.MediaType)
|
||||||
|
}
|
||||||
|
|
||||||
|
if w.Header().Get("Content-Length") == "" {
|
||||||
|
// Set the content length if not already set.
|
||||||
|
w.Header().Set("Content-Length", fmt.Sprint(desc.Size))
|
||||||
|
}
|
||||||
|
|
||||||
|
http.ServeContent(w, r, desc.Digest.String(), time.Time{}, br)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue