e809796f59
Push, pull and delete of manifest files in the registry have been implemented on top of the storage services. Basic workflows, including reporting of missing manifests are tested, including various proposed response codes. Common testing functionality has been collected into shared methods. A test suite may be emerging but it might better to capture more edge cases (such as resumable upload, range requests, etc.) before we commit to a full approach. To support clearer test cases and simpler handler methods, an application aware urlBuilder has been added. We may want to export the functionality for use in the client, which could allow us to abstract away from gorilla/mux. A few error codes have been added to fill in error conditions missing from the proposal. Some use cases have identified some problems with the approach to error reporting that requires more work to reconcile. To resolve this, the mapping of Go errors into error types needs to pulled out of the handlers and into the application. We also need to move to type-based errors, with rich information, rather than value-based errors. ErrorHandlers will probably replace the http.Handlers to make this work correctly. Unrelated to the above, the "length" parameter has been migrated to "size" for completing layer uploads. This change should have gone out before but these diffs ending up being coupled with the parameter name change due to updates to the layer unit tests.
61 lines
1.4 KiB
Go
61 lines
1.4 KiB
Go
package registry
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/docker/docker-registry/digest"
|
|
"github.com/docker/docker-registry/storage"
|
|
"github.com/gorilla/handlers"
|
|
)
|
|
|
|
// layerDispatcher uses the request context to build a layerHandler.
|
|
func layerDispatcher(ctx *Context, r *http.Request) http.Handler {
|
|
dgst, err := digest.ParseDigest(ctx.vars["digest"])
|
|
|
|
if err != nil {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
ctx.Errors.Push(ErrorCodeInvalidDigest, err)
|
|
})
|
|
}
|
|
|
|
layerHandler := &layerHandler{
|
|
Context: ctx,
|
|
Digest: dgst,
|
|
}
|
|
|
|
layerHandler.log = layerHandler.log.WithField("digest", dgst)
|
|
|
|
return handlers.MethodHandler{
|
|
"GET": http.HandlerFunc(layerHandler.GetLayer),
|
|
"HEAD": http.HandlerFunc(layerHandler.GetLayer),
|
|
}
|
|
}
|
|
|
|
// layerHandler serves http layer requests.
|
|
type layerHandler struct {
|
|
*Context
|
|
|
|
Digest digest.Digest
|
|
}
|
|
|
|
// GetLayer fetches the binary data from backend storage returns it in the
|
|
// response.
|
|
func (lh *layerHandler) GetLayer(w http.ResponseWriter, r *http.Request) {
|
|
layers := lh.services.Layers()
|
|
|
|
layer, err := layers.Fetch(lh.Name, lh.Digest)
|
|
|
|
if err != nil {
|
|
switch err := err.(type) {
|
|
case storage.ErrUnknownLayer:
|
|
w.WriteHeader(http.StatusNotFound)
|
|
lh.Errors.Push(ErrorCodeUnknownLayer, err.FSLayer)
|
|
default:
|
|
lh.Errors.Push(ErrorCodeUnknown, err)
|
|
}
|
|
return
|
|
}
|
|
defer layer.Close()
|
|
|
|
http.ServeContent(w, r, layer.Digest().String(), layer.CreatedAt(), layer)
|
|
}
|