From 902437031ecb8fbed0a0dc7ce14260556179aa0c Mon Sep 17 00:00:00 2001 From: orenbm Date: Tue, 4 Aug 2020 00:16:56 +0300 Subject: [PATCH] Accept multiple Content-Types for building an image Currently we accept only the 'application/x-tar' header when sending the tar file for building an image. However, this header has the aliases 'application/tar' and 'application/x-gtar' so we should accept those as well. Furthermore, docker-compose uses 'application/tar' so accepting this content-type will take us one step further in supporting docker-compose with the Podman API. Signed-off-by: orenbm --- pkg/api/handlers/compat/images_build.go | 16 ++++++++++++++-- pkg/api/server/docs.go | 2 ++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/pkg/api/handlers/compat/images_build.go b/pkg/api/handlers/compat/images_build.go index 3005063a79..0557d52d4f 100644 --- a/pkg/api/handlers/compat/images_build.go +++ b/pkg/api/handlers/compat/images_build.go @@ -33,9 +33,21 @@ func BuildImage(w http.ResponseWriter, r *http.Request) { } if hdr, found := r.Header["Content-Type"]; found && len(hdr) > 0 { - if hdr[0] != "application/x-tar" { + validContentTypes := []string{ + "application/tar", + "application/x-tar", + "application/x-gtar", + } + + isValidContentType := false + for _, validContentType := range validContentTypes { + if validContentType == hdr[0] { + isValidContentType = true + } + } + if !isValidContentType { utils.BadRequest(w, "Content-Type", hdr[0], - fmt.Errorf("Content-Type: %s is not supported. Should be \"application/x-tar\"", hdr[0])) + fmt.Errorf("Content-Type: %s is not supported. Should be one of %s", hdr[0], validContentTypes)) return } } diff --git a/pkg/api/server/docs.go b/pkg/api/server/docs.go index 1aaf31117e..af7468f7aa 100644 --- a/pkg/api/server/docs.go +++ b/pkg/api/server/docs.go @@ -52,6 +52,8 @@ // // Consumes: // - application/json +// - application/tar // - application/x-tar +// - application/x-gtar // swagger:meta package server