Skip to content

Commit

Permalink
API: containers/json always set application/json content type
Browse files Browse the repository at this point in the history
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 containers#14647

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
  • Loading branch information
Luap99 committed Jun 20, 2022
1 parent 55052c6 commit bb5bd09
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 0 additions & 4 deletions pkg/api/handlers/libpod/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
7 changes: 6 additions & 1 deletion test/apiv2/20-containers.at
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down

0 comments on commit bb5bd09

Please sign in to comment.