|
@@ -9,6 +9,7 @@ import (
|
|
|
"io"
|
|
|
"io/ioutil"
|
|
|
"log"
|
|
|
+ "mime"
|
|
|
"net"
|
|
|
"net/http"
|
|
|
"os"
|
|
@@ -81,6 +82,14 @@ func getBoolParam(value string) (bool, error) {
|
|
|
return ret, nil
|
|
|
}
|
|
|
|
|
|
+func matchesContentType(contentType, expectedType string) bool {
|
|
|
+ mimetype, _, err := mime.ParseMediaType(contentType)
|
|
|
+ if err != nil {
|
|
|
+ utils.Debugf("Error parsing media type: %s error: %s", contentType, err.Error())
|
|
|
+ }
|
|
|
+ return err == nil && mimetype == expectedType
|
|
|
+}
|
|
|
+
|
|
|
func postAuth(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
authConfig := &auth.AuthConfig{}
|
|
|
err := json.NewDecoder(r.Body).Decode(authConfig)
|
|
@@ -594,7 +603,7 @@ func postContainersStart(srv *Server, version float64, w http.ResponseWriter, r
|
|
|
|
|
|
// allow a nil body for backwards compatibility
|
|
|
if r.Body != nil {
|
|
|
- if r.Header.Get("Content-Type") == "application/json" {
|
|
|
+ if matchesContentType(r.Header.Get("Content-Type"), "application/json") {
|
|
|
if err := json.NewDecoder(r.Body).Decode(hostConfig); err != nil {
|
|
|
return err
|
|
|
}
|