From 4d5a18b14301ab497e1ddd7bd73a8a484f878fbb Mon Sep 17 00:00:00 2001 From: Teppei Fukuda Date: Mon, 29 Jul 2024 14:51:49 +0400 Subject: [PATCH] feat: add Content-Type (#19) --- registry/router.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/registry/router.go b/registry/router.go index 9ff780b..88b84b1 100644 --- a/registry/router.go +++ b/registry/router.go @@ -2,6 +2,7 @@ package registry import ( "context" + "encoding/json" "fmt" "io" "net/http" @@ -72,11 +73,19 @@ func (s *registryRouter) manifestHandler(ctx context.Context, w http.ResponseWri return errdefs.NotFound(xerrors.Errorf("unknown image: %s", filePath)) } - b, err := img.RawManifest() + m, err := img.Manifest() if err != nil { return errdefs.Unavailable(err) } + w.Header().Set("Content-Type", string(m.MediaType)) + w.WriteHeader(http.StatusOK) + + // Use json.Marshal instead of json.NewEncoder to avoid writing a newline + b, err := json.Marshal(m) + if err != nil { + return errdefs.Unavailable(err) + } if _, err = w.Write(b); err != nil { return errdefs.Unavailable(err) }