Skip to content

Commit

Permalink
feat: add Content-Type (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
knqyf263 authored Jul 29, 2024
1 parent 547f233 commit 4d5a18b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion registry/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package registry

import (
"context"
"encoding/json"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 4d5a18b

Please sign in to comment.