Skip to content

Commit

Permalink
Fix head
Browse files Browse the repository at this point in the history
  • Loading branch information
wzshiming committed Apr 23, 2024
1 parent f3ec1dc commit 80af290
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions pkg/handler/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ func (h *Handler) forwardBlob(w http.ResponseWriter, r *http.Request, image, has
return
}
w.Header().Set("Content-Type", string(mediaType))
if r.Method == http.MethodHead {
return
}

if strings.HasSuffix(string(mediaType), "gzip") {
r, err := layer.Compressed()
if err != nil {
Expand All @@ -97,8 +101,7 @@ func (h *Handler) forwardBlob(w http.ResponseWriter, r *http.Request, image, has

_, err = io.Copy(w, r)
if err != nil {
_ = regErrInternal(err).Write(w)
return
slog.Error("io.Copy", "err", err)
}
} else {
r, err := layer.Uncompressed()
Expand All @@ -109,8 +112,7 @@ func (h *Handler) forwardBlob(w http.ResponseWriter, r *http.Request, image, has

_, err = io.Copy(w, r)
if err != nil {
_ = regErrInternal(err).Write(w)
return
slog.Error("io.Copy", "err", err)
}
}
}
Expand All @@ -134,14 +136,21 @@ func (h *Handler) forwardManifestBlob(w http.ResponseWriter, r *http.Request, im
return
}

w.Header().Set("Content-Type", string(desc.MediaType))
if r.Method == http.MethodHead {
return
}

manifest, err := desc.RawManifest()
if err != nil {
_ = regErrInternal(err).Write(w)
return
}

w.Header().Set("Content-Type", string(desc.MediaType))
w.Write(manifest)
_, err = w.Write(manifest)
if err != nil {
slog.Error("w.Write", "err", err)
}
}

func (h *Handler) forwardManifest(w http.ResponseWriter, r *http.Request, image, tag string, action *pattern.Action) {
Expand All @@ -167,6 +176,10 @@ func (h *Handler) forwardManifest(w http.ResponseWriter, r *http.Request, image,
}

desc, err = puller.Get(r.Context(), refDestination)
if err != nil {
_ = regErrInternal(err).Write(w)
return
}
}

manifest, err := desc.RawManifest()
Expand All @@ -176,11 +189,13 @@ func (h *Handler) forwardManifest(w http.ResponseWriter, r *http.Request, image,
}

w.Header().Set("Content-Type", string(desc.MediaType))
if r.Method == http.MethodHead {
return
}

_, err = w.Write(manifest)
if err != nil {
_ = regErrInternal(err).Write(w)
return
slog.Error("w.Write", "err", err)
}
}

Expand Down

0 comments on commit 80af290

Please sign in to comment.