Skip to content

Commit

Permalink
Accept multiple Content-Types for building an image
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
orenbm committed Aug 3, 2020
1 parent 1709335 commit 9024370
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 14 additions & 2 deletions pkg/api/handlers/compat/images_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/api/server/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
//
// Consumes:
// - application/json
// - application/tar
// - application/x-tar
// - application/x-gtar
// swagger:meta
package server

0 comments on commit 9024370

Please sign in to comment.