Skip to content

Commit

Permalink
Merge pull request docker-archive#1032 from vieux/fix_match_push
Browse files Browse the repository at this point in the history
fix image matching in push
  • Loading branch information
abronan committed Jul 15, 2015
2 parents 2037540 + a54763c commit 02ba1fa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
28 changes: 14 additions & 14 deletions api/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,6 @@ func getVersion(c *context, w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(version)
}

// GET /images/{name:.*}/get
func getImage(c *context, w http.ResponseWriter, r *http.Request) {
name := mux.Vars(r)["name"]

for _, image := range c.cluster.Images() {
if len(strings.SplitN(name, ":", 2)) == 2 && image.Match(name, true) ||
len(strings.SplitN(name, ":", 2)) == 1 && image.Match(name, false) {
proxy(c.tlsConfig, image.Engine.Addr, w, r)
return
}
}
httpError(w, fmt.Sprintf("No such image: %s", name), http.StatusNotFound)
}

// GET /images/get
func getImages(c *context, w http.ResponseWriter, r *http.Request) {
if err := r.ParseForm(); err != nil {
Expand Down Expand Up @@ -577,6 +563,20 @@ 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) {
name := mux.Vars(r)["name"]

for _, image := range c.cluster.Images() {
if len(strings.SplitN(name, ":", 2)) == 2 && image.Match(name, true) ||
len(strings.SplitN(name, ":", 2)) == 1 && image.Match(name, false) {
proxy(c.tlsConfig, image.Engine.Addr, w, r)
return
}
}
httpError(w, fmt.Sprintf("No such image: %s", name), http.StatusNotFound)
}

// Proxy a request to the right node and force refresh
func proxyImageAndForceRefresh(c *context, w http.ResponseWriter, r *http.Request) {
name := mux.Vars(r)["name"]
Expand Down
4 changes: 2 additions & 2 deletions api/primary.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var routes = map[string]map[string]handler{
"/images/viz": notImplementedHandler,
"/images/search": proxyRandom,
"/images/get": getImages,
"/images/{name:.*}/get": getImage,
"/images/{name:.*}/get": proxyImageTagOptional,
"/images/{name:.*}/history": proxyImage,
"/images/{name:.*}/json": proxyImage,
"/containers/ps": getContainersJSON,
Expand All @@ -50,7 +50,7 @@ var routes = map[string]map[string]handler{
"/build": proxyRandomAndForceRefresh,
"/images/create": postImagesCreate,
"/images/load": postImagesLoad,
"/images/{name:.*}/push": proxyImage,
"/images/{name:.*}/push": proxyImageTagOptional,
"/images/{name:.*}/tag": proxyImageAndForceRefresh,
"/containers/create": postContainersCreate,
"/containers/{name:.*}/kill": proxyContainerAndForceRefresh,
Expand Down

0 comments on commit 02ba1fa

Please sign in to comment.