refactor(server): Pass HTTP request to storage.ServeLayer
The request object is required for some serving methods (e.g. the filesystem one).
This commit is contained in:
parent
e5bb2fc887
commit
167a0b3263
4 changed files with 6 additions and 4 deletions
|
@ -411,7 +411,7 @@ func uploadHashLayer(ctx context.Context, s *State, key string, lw layerWriter)
|
|||
"layer": key,
|
||||
"sha256": sha256sum,
|
||||
"size": size,
|
||||
}).Info("uploaded layer")
|
||||
}).Info("created and persisted layer")
|
||||
|
||||
entry := manifest.Entry{
|
||||
Digest: "sha256:" + sha256sum,
|
||||
|
|
|
@ -175,7 +175,7 @@ func (h *registryHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
if len(layerMatches) == 3 {
|
||||
digest := layerMatches[2]
|
||||
storage := h.state.Storage
|
||||
err := storage.ServeLayer(digest, w)
|
||||
err := storage.ServeLayer(digest, r, w)
|
||||
if err != nil {
|
||||
log.WithError(err).WithFields(log.Fields{
|
||||
"layer": digest,
|
||||
|
|
|
@ -139,7 +139,7 @@ func (b *GCSBackend) Move(old, new string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (b *GCSBackend) ServeLayer(digest string, w http.ResponseWriter) error {
|
||||
func (b *GCSBackend) ServeLayer(digest string, r *http.Request, w http.ResponseWriter) error {
|
||||
url, err := b.constructLayerUrl(digest)
|
||||
if err != nil {
|
||||
log.WithError(err).WithFields(log.Fields{
|
||||
|
@ -150,6 +150,8 @@ func (b *GCSBackend) ServeLayer(digest string, w http.ResponseWriter) error {
|
|||
return err
|
||||
}
|
||||
|
||||
log.WithField("layer", digest).Info("redirecting layer request to GCS bucket")
|
||||
|
||||
w.Header().Set("Location", url)
|
||||
w.WriteHeader(303)
|
||||
return nil
|
||||
|
|
|
@ -30,5 +30,5 @@ type Backend interface {
|
|||
|
||||
// Serve provides a handler function to serve HTTP requests
|
||||
// for layers in the storage backend.
|
||||
ServeLayer(digest string, w http.ResponseWriter) error
|
||||
ServeLayer(digest string, r *http.Request, w http.ResponseWriter) error
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue