forked from TrueCloudLab/distribution
Final polish to cloudfront and larger middleware refactor
Signed-off-by: David Lawrence <david.lawrence@docker.com> (github: endophage)
This commit is contained in:
parent
30bcc17b85
commit
6a72d1aefb
2 changed files with 18 additions and 18 deletions
|
@ -49,8 +49,8 @@ type layerHandler struct {
|
||||||
// response.
|
// response.
|
||||||
func (lh *layerHandler) GetLayer(w http.ResponseWriter, r *http.Request) {
|
func (lh *layerHandler) GetLayer(w http.ResponseWriter, r *http.Request) {
|
||||||
ctxu.GetLogger(lh).Debug("GetImageLayer")
|
ctxu.GetLogger(lh).Debug("GetImageLayer")
|
||||||
layerStore := lh.Repository.Layers()
|
layers := lh.Repository.Layers()
|
||||||
layerReader, err := layerStore.Fetch(lh.Digest)
|
layer, err := layers.Fetch(lh.Digest)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
switch err := err.(type) {
|
switch err := err.(type) {
|
||||||
|
@ -63,5 +63,5 @@ func (lh *layerHandler) GetLayer(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
layerReader.ServeHTTP(w, r)
|
layer.ServeHTTP(w, r)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"github.com/docker/distribution/digest"
|
"github.com/docker/distribution/digest"
|
||||||
)
|
)
|
||||||
|
|
||||||
// LayerRead implements Layer and provides facilities for reading and
|
// layerReader implements Layer and provides facilities for reading and
|
||||||
// seeking.
|
// seeking.
|
||||||
type layerReader struct {
|
type layerReader struct {
|
||||||
fileReader
|
fileReader
|
||||||
|
@ -18,32 +18,32 @@ type layerReader struct {
|
||||||
|
|
||||||
var _ distribution.Layer = &layerReader{}
|
var _ distribution.Layer = &layerReader{}
|
||||||
|
|
||||||
func (lrs *layerReader) Path() string {
|
func (lr *layerReader) Path() string {
|
||||||
return lrs.path
|
return lr.path
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lrs *layerReader) Digest() digest.Digest {
|
func (lr *layerReader) Digest() digest.Digest {
|
||||||
return lrs.digest
|
return lr.digest
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lrs *layerReader) Length() int64 {
|
func (lr *layerReader) Length() int64 {
|
||||||
return lrs.size
|
return lr.size
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lrs *layerReader) CreatedAt() time.Time {
|
func (lr *layerReader) CreatedAt() time.Time {
|
||||||
return lrs.modtime
|
return lr.modtime
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close the layer. Should be called when the resource is no longer needed.
|
// Close the layer. Should be called when the resource is no longer needed.
|
||||||
func (lrs *layerReader) Close() error {
|
func (lr *layerReader) Close() error {
|
||||||
return lrs.closeWithErr(distribution.ErrLayerClosed)
|
return lr.closeWithErr(distribution.ErrLayerClosed)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lrs *layerReader) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (lr *layerReader) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Docker-Content-Digest", lrs.digest.String())
|
w.Header().Set("Docker-Content-Digest", lr.digest.String())
|
||||||
|
|
||||||
if url, err := lrs.fileReader.driver.URLFor(lrs.Path(), map[string]interface{}{}); err == nil {
|
if url, err := lr.fileReader.driver.URLFor(lr.Path(), map[string]interface{}{}); err == nil {
|
||||||
http.Redirect(w, r, url, http.StatusTemporaryRedirect)
|
http.Redirect(w, r, url, http.StatusTemporaryRedirect)
|
||||||
}
|
}
|
||||||
http.ServeContent(w, r, lrs.Digest().String(), lrs.CreatedAt(), lrs)
|
http.ServeContent(w, r, lr.digest.String(), lr.CreatedAt(), lr)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue