Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For compatibility, ignore Content-Type #11167

Merged
merged 1 commit into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions pkg/api/handlers/compat/images_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,16 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
contentType := hdr[0]
switch contentType {
case "application/tar":
logrus.Warnf("tar file content type is %s, should use \"application/x-tar\" content type", contentType)
logrus.Infof("tar file content type is %s, should use \"application/x-tar\" content type", contentType)
case "application/x-tar":
break
default:
utils.BadRequest(w, "Content-Type", hdr[0],
fmt.Errorf("Content-Type: %s is not supported. Should be \"application/x-tar\"", hdr[0]))
return
if utils.IsLibpodRequest(r) {
utils.BadRequest(w, "Content-Type", hdr[0],
fmt.Errorf("Content-Type: %s is not supported. Should be \"application/x-tar\"", hdr[0]))
return
}
logrus.Infof("tar file content type is %s, should use \"application/x-tar\" content type", contentType)
}
}

Expand Down
34 changes: 33 additions & 1 deletion test/apiv2/10-images.at
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ curl -XPOST --data-binary @<(cat $CONTAINERFILE_TAR) \
BUILD_TEST_ERROR=""

if ! grep -q '200 OK' "${TMPD}/headers.txt"; then
echo -e "${red}NOK: Image build from tar failed response was not 200 OK"
echo -e "${red}NOK: Image build from tar failed response was not 200 OK (application/x-tar)"
BUILD_TEST_ERROR="1"
fi

Expand All @@ -182,6 +182,38 @@ if ! grep -q 'quay.io/libpod/alpine_labels' "${TMPD}/response.txt"; then
BUILD_TEST_ERROR="1"
fi

curl -XPOST --data-binary @<(cat $CONTAINERFILE_TAR) \
-H "content-type: application/tar" \
--dump-header "${TMPD}/headers.txt" \
-o /dev/null \
"http://$HOST:$PORT/v1.40/libpod/build?dockerfile=containerfile" &> /dev/null
if ! grep -q '200 OK' "${TMPD}/headers.txt"; then
echo -e "${red}NOK: Image build from tar failed response was not 200 OK (application/tar)"
BUILD_TEST_ERROR="1"
fi

# Yes, this is very un-RESTful re: Content-Type header ignored when compatibility endpoint used
# See https://github.com/containers/podman/issues/11012
curl -XPOST --data-binary @<(cat $CONTAINERFILE_TAR) \
-H "content-type: application/json" \
--dump-header "${TMPD}/headers.txt" \
-o /dev/null \
"http://$HOST:$PORT/v1.40/build?dockerfile=containerfile" &> /dev/null
if ! grep -q '200 OK' "${TMPD}/headers.txt"; then
echo -e "${red}NOK: Image build from tar failed response was not 200 OK (application/tar)"
BUILD_TEST_ERROR="1"
fi

curl -XPOST --data-binary @<(cat $CONTAINERFILE_TAR) \
-H "content-type: application/json" \
--dump-header "${TMPD}/headers.txt" \
-o /dev/null \
"http://$HOST:$PORT/v1.40/libpod/build?dockerfile=containerfile" &> /dev/null
if ! grep -q '400 Bad Request' "${TMPD}/headers.txt"; then
echo -e "${red}NOK: Image build should have failed with 400 (wrong Content-Type)"
BUILD_TEST_ERROR="1"
fi

cleanBuildTest
if [[ "${BUILD_TEST_ERROR}" ]]; then
exit 1
Expand Down