diff options
author | Paul Holzinger <pholzing@redhat.com> | 2022-06-20 14:03:05 +0200 |
---|---|---|
committer | Paul Holzinger <pholzing@redhat.com> | 2022-06-20 14:07:56 +0200 |
commit | bb5bd09eade239dda07332a887d0fafb6e29ee87 (patch) | |
tree | 0222bfb3e5738c36641aaeea1269ee43b3296bfc | |
parent | 55052c6b9807b5a51b50abc90e391e872be450c2 (diff) | |
download | podman-bb5bd09eade239dda07332a887d0fafb6e29ee87.tar.gz podman-bb5bd09eade239dda07332a887d0fafb6e29ee87.tar.bz2 podman-bb5bd09eade239dda07332a887d0fafb6e29ee87.zip |
API: containers/json always set application/json content type
When we return no containers we just return `[]` but we still have to keep
the content type header `application/json` so external tools can correctly
parse the output.
Fixes #14647
Signed-off-by: Paul Holzinger <pholzing@redhat.com>
-rw-r--r-- | pkg/api/handlers/libpod/containers.go | 4 | ||||
-rw-r--r-- | test/apiv2/20-containers.at | 7 |
2 files changed, 6 insertions, 5 deletions
diff --git a/pkg/api/handlers/libpod/containers.go b/pkg/api/handlers/libpod/containers.go index 6b5bee403..deddcaf93 100644 --- a/pkg/api/handlers/libpod/containers.go +++ b/pkg/api/handlers/libpod/containers.go @@ -115,10 +115,6 @@ func ListContainers(w http.ResponseWriter, r *http.Request) { utils.InternalServerError(w, err) return } - if len(pss) == 0 { - utils.WriteResponse(w, http.StatusOK, "[]") - return - } utils.WriteResponse(w, http.StatusOK, pss) } diff --git a/test/apiv2/20-containers.at b/test/apiv2/20-containers.at index 383c527b4..80bbcd60e 100644 --- a/test/apiv2/20-containers.at +++ b/test/apiv2/20-containers.at @@ -16,7 +16,12 @@ podman pull $ENV_WORKDIR_IMG &>/dev/null # Ensure clean slate podman rm -a -f &>/dev/null -t GET "libpod/containers/json (at start: clean slate)" 200 length=0 +t GET "libpod/containers/json (at start: clean slate)" 200 \ + "[]" \ + length=0 +# check content type: https://github.com/containers/podman/issues/14647 +response_headers=$(cat "$WORKDIR/curl.headers.out") +like "$response_headers" ".*Content-Type: application/json.*" "header does not contain application/json" # Regression test for #12904 (race condition in logging code) mytext="hi-there-$(random_string 15)" |