diff --git a/api/handlers.go b/api/handlers.go index 846cf92211..941af22db8 100644 --- a/api/handlers.go +++ b/api/handlers.go @@ -817,8 +817,8 @@ func proxyImage(c *context, w http.ResponseWriter, r *http.Request) { httpError(w, fmt.Sprintf("No such image: %s", name), http.StatusNotFound) } -// Proxy a request to the right node -func proxyImageTagOptional(c *context, w http.ResponseWriter, r *http.Request) { +// Proxy get image request to the right node +func proxyImageGet(c *context, w http.ResponseWriter, r *http.Request) { name := mux.Vars(r)["name"] for _, image := range c.cluster.Images() { @@ -831,6 +831,30 @@ func proxyImageTagOptional(c *context, w http.ResponseWriter, r *http.Request) { httpError(w, fmt.Sprintf("No such image: %s", name), http.StatusNotFound) } +// Proxy push image request to the right node +func proxyImagePush(c *context, w http.ResponseWriter, r *http.Request) { + name := mux.Vars(r)["name"] + + if err := r.ParseForm(); err != nil { + httpError(w, err.Error(), http.StatusInternalServerError) + return + } + tag := r.Form.Get("tag") + if tag != "" { + name = name + ":" + tag + } + + for _, image := range c.cluster.Images() { + if tag != "" && image.Match(name, true) || + tag == "" && image.Match(name, false) { + proxy(c.tlsConfig, image.Engine.Addr, w, r) + return + } + } + + httpError(w, fmt.Sprintf("No such image: %s", name), http.StatusNotFound) +} + // POST /images/{name:.*}/tag func postTagImage(c *context, w http.ResponseWriter, r *http.Request) { name := mux.Vars(r)["name"] diff --git a/api/primary.go b/api/primary.go index 92b5dc00a2..d741282bc7 100644 --- a/api/primary.go +++ b/api/primary.go @@ -33,7 +33,7 @@ var routes = map[string]map[string]handler{ "/images/viz": notImplementedHandler, "/images/search": proxyRandom, "/images/get": getImages, - "/images/{name:.*}/get": proxyImageTagOptional, + "/images/{name:.*}/get": proxyImageGet, "/images/{name:.*}/history": proxyImage, "/images/{name:.*}/json": proxyImage, "/containers/ps": getContainersJSON, @@ -58,7 +58,7 @@ var routes = map[string]map[string]handler{ "/build": postBuild, "/images/create": postImagesCreate, "/images/load": postImagesLoad, - "/images/{name:.*}/push": proxyImageTagOptional, + "/images/{name:.*}/push": proxyImagePush, "/images/{name:.*}/tag": postTagImage, "/containers/create": postContainersCreate, "/containers/{name:.*}/kill": proxyContainerAndForceRefresh,