From f10c174c0ed24bc464ca3a5f76393b19ca911151 Mon Sep 17 00:00:00 2001 From: Ramkumar Chinchani Date: Fri, 23 Jul 2021 04:01:35 +0000 Subject: [PATCH] routes: add Content-Type header for HEAD manifest response With recent docker client-side changes, on 'docker pull' we see: "Error response from daemon: missing or empty Content-Type header" Hence, set Content-Type header. Signed-off-by: Ramkumar Chinchani --- pkg/api/routes.go | 3 ++- pkg/compliance/v1_0_0/check.go | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/api/routes.go b/pkg/api/routes.go index f3803ea7..a16a5aae 100644 --- a/pkg/api/routes.go +++ b/pkg/api/routes.go @@ -267,7 +267,7 @@ func (rh *RouteHandler) CheckManifest(w http.ResponseWriter, r *http.Request) { return } - _, digest, _, err := is.GetImageManifest(name, reference) + _, digest, mediaType, err := is.GetImageManifest(name, reference) if err != nil { switch err { case errors.ErrRepoNotFound: @@ -287,6 +287,7 @@ func (rh *RouteHandler) CheckManifest(w http.ResponseWriter, r *http.Request) { w.Header().Set(DistContentDigestKey, digest) w.Header().Set("Content-Length", "0") + w.Header().Set("Content-Type", mediaType) w.WriteHeader(http.StatusOK) } diff --git a/pkg/compliance/v1_0_0/check.go b/pkg/compliance/v1_0_0/check.go index 17fe87a2..c87cfcc6 100644 --- a/pkg/compliance/v1_0_0/check.go +++ b/pkg/compliance/v1_0_0/check.go @@ -550,6 +550,7 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { resp, err = resty.R().Head(baseURL + "/v2/repo7/manifests/test:1.0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) + So(resp.Header().Get("Content-Type"), ShouldNotBeEmpty) resp, err = resty.R().Get(baseURL + "/v2/repo7/manifests/test:1.0") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) @@ -558,6 +559,7 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { resp, err = resty.R().Head(baseURL + "/v2/repo7/manifests/" + digest.String()) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) + So(resp.Header().Get("Content-Type"), ShouldNotBeEmpty) resp, err = resty.R().Get(baseURL + "/v2/repo7/manifests/" + digest.String()) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200)