Browse code

Merge pull request #948 from dotcloud/registry_pathencode

* Registry: Use opaque requests when we need to preserve urlencoding in registry requests

Solomon Hykes authored on 2013/06/20 14:41:16
Showing 2 changed files
... ...
@@ -156,7 +156,7 @@ func (r *Registry) GetRemoteTags(registries []string, repository string, token [
156 156
 	}
157 157
 	for _, host := range registries {
158 158
 		endpoint := fmt.Sprintf("https://%s/v1/repositories/%s/tags", host, repository)
159
-		req, err := http.NewRequest("GET", endpoint, nil)
159
+		req, err := r.opaqueRequest("GET", endpoint, nil)
160 160
 		if err != nil {
161 161
 			return nil, err
162 162
 		}
... ...
@@ -190,7 +190,7 @@ func (r *Registry) GetRemoteTags(registries []string, repository string, token [
190 190
 func (r *Registry) GetRepositoryData(remote string) (*RepositoryData, error) {
191 191
 	repositoryTarget := auth.IndexServerAddress() + "/repositories/" + remote + "/images"
192 192
 
193
-	req, err := http.NewRequest("GET", repositoryTarget, nil)
193
+	req, err := r.opaqueRequest("GET", repositoryTarget, nil)
194 194
 	if err != nil {
195 195
 		return nil, err
196 196
 	}
... ...
@@ -309,6 +309,15 @@ func (r *Registry) PushImageLayerRegistry(imgId string, layer io.Reader, registr
309 309
 	return nil
310 310
 }
311 311
 
312
+func (r *Registry) opaqueRequest(method, urlStr string, body io.Reader) (*http.Request, error) {
313
+	req, err := http.NewRequest(method, urlStr, body)
314
+	if err != nil {
315
+		return nil, err
316
+	}
317
+	req.URL.Opaque = strings.Replace(urlStr, req.URL.Scheme + ":", "", 1)
318
+	return req, err
319
+}
320
+
312 321
 // push a tag on the registry.
313 322
 // Remote has the format '<user>/<repo>
314 323
 func (r *Registry) PushRegistryTag(remote, revision, tag, registry string, token []string) error {
... ...
@@ -316,7 +325,7 @@ func (r *Registry) PushRegistryTag(remote, revision, tag, registry string, token
316 316
 	revision = "\"" + revision + "\""
317 317
 	registry = "https://" + registry + "/v1"
318 318
 
319
-	req, err := http.NewRequest("PUT", registry+"/repositories/"+remote+"/tags/"+tag, strings.NewReader(revision))
319
+	req, err := r.opaqueRequest("PUT", registry+"/repositories/"+remote+"/tags/"+tag, strings.NewReader(revision))
320 320
 	if err != nil {
321 321
 		return err
322 322
 	}
... ...
@@ -346,7 +355,7 @@ func (r *Registry) PushImageJSONIndex(remote string, imgList []*ImgData, validat
346 346
 
347 347
 	utils.Debugf("Image list pushed to index:\n%s\n", imgListJSON)
348 348
 
349
-	req, err := http.NewRequest("PUT", auth.IndexServerAddress()+"/repositories/"+remote+"/"+suffix, bytes.NewReader(imgListJSON))
349
+	req, err := r.opaqueRequest("PUT", auth.IndexServerAddress()+"/repositories/"+remote+"/"+suffix, bytes.NewReader(imgListJSON))
350 350
 	if err != nil {
351 351
 		return nil, err
352 352
 	}
... ...
@@ -366,7 +375,7 @@ func (r *Registry) PushImageJSONIndex(remote string, imgList []*ImgData, validat
366 366
 	// Redirect if necessary
367 367
 	for res.StatusCode >= 300 && res.StatusCode < 400 {
368 368
 		utils.Debugf("Redirected to %s\n", res.Header.Get("Location"))
369
-		req, err = http.NewRequest("PUT", res.Header.Get("Location"), bytes.NewReader(imgListJSON))
369
+		req, err = r.opaqueRequest("PUT", res.Header.Get("Location"), bytes.NewReader(imgListJSON))
370 370
 		if err != nil {
371 371
 			return nil, err
372 372
 		}
... ...
@@ -572,7 +572,7 @@ func (srv *Server) pushRepository(r *registry.Registry, out io.Writer, name stri
572 572
 				// FIXME: Continue on error?
573 573
 				return err
574 574
 			}
575
-			out.Write(sf.FormatStatus("Pushing tags for rev [%s] on {%s}", elem.ID, ep+"/users/"+srvName+"/"+elem.Tag))
575
+			out.Write(sf.FormatStatus("Pushing tags for rev [%s] on {%s}", elem.ID, ep+"/repositories/"+srvName+"/tags/"+elem.Tag))
576 576
 			if err := r.PushRegistryTag(srvName, elem.ID, elem.Tag, ep, repoData.Tokens); err != nil {
577 577
 				return err
578 578
 			}