From 4df93cb58fdf14494977de0789ca5edc5d0fee3a Mon Sep 17 00:00:00 2001 From: Antonio Murdaca Date: Wed, 22 Jul 2015 11:07:41 +0200 Subject: [PATCH] Fix wrong Content-Type returned by /images/search API /images/search was replying with Content-Type text/plain instead of application/json. Fix #14846 Signed-off-by: Antonio Murdaca Upstream-commit: 1a5d6a94c9e4c099354d9125ea857f6277eca0b7 Component: engine --- components/engine/api/server/server.go | 2 +- .../engine/integration-cli/docker_api_images_test.go | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/components/engine/api/server/server.go b/components/engine/api/server/server.go index 1407c614cf..a617d132e3 100644 --- a/components/engine/api/server/server.go +++ b/components/engine/api/server/server.go @@ -818,7 +818,7 @@ func (s *Server) getImagesSearch(version version.Version, w http.ResponseWriter, if err != nil { return err } - return json.NewEncoder(w).Encode(query.Results) + return writeJSON(w, http.StatusOK, query.Results) } func (s *Server) postImagesPush(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error { diff --git a/components/engine/integration-cli/docker_api_images_test.go b/components/engine/integration-cli/docker_api_images_test.go index 8b1985569c..1536c0cd65 100644 --- a/components/engine/integration-cli/docker_api_images_test.go +++ b/components/engine/integration-cli/docker_api_images_test.go @@ -120,3 +120,14 @@ func (s *DockerSuite) TestApiImagesHistory(c *check.C) { c.Assert(len(historydata), check.Not(check.Equals), 0) c.Assert(historydata[0].Tags[0], check.Equals, "test-api-images-history:latest") } + +// #14846 +func (s *DockerSuite) TestApiImagesSearchJSONContentType(c *check.C) { + testRequires(c, Network) + + res, b, err := sockRequestRaw("GET", "/images/search?term=test", nil, "application/json") + b.Close() + c.Assert(err, check.IsNil) + c.Assert(res.StatusCode, check.Equals, http.StatusOK) + c.Assert(res.Header.Get("Content-Type"), check.Equals, "application/json") +}