[lxc-devel] [lxd/master] Normalize the URLs in the client
stgraber on Github
lxc-bot at linuxcontainers.org
Mon Jun 13 17:49:26 UTC 2016
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 435 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160613/85bca886/attachment.bin>
-------------- next part --------------
From 61d22f1df240fc52e4cafbbefe9589bec3d2e088 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Mon, 13 Jun 2016 13:48:06 -0400
Subject: [PATCH] Normalize the URLs in the client
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This avoids generating URLs which Go then drops on the floor.
Closes #2112
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
client.go | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/client.go b/client.go
index 22f3fbb..eefaa16 100644
--- a/client.go
+++ b/client.go
@@ -489,17 +489,32 @@ func (c *Client) websocket(operation string, secret string) (*websocket.Conn, er
}
func (c *Client) url(elem ...string) string {
+ // Normalize the URL
path := strings.Join(elem, "/")
+ entries := []string{}
+ for _, entry := range strings.Split(path, "/") {
+ if entry == "" {
+ continue
+ }
+
+ entries = append(entries, entry)
+ }
+ path = strings.Join(entries, "/")
+
+ // Assemble the final URL
uri := c.BaseURL + "/" + path
+ // Aliases may contain a trailing slash
if strings.HasPrefix(path, "1.0/images/aliases") {
return uri
}
+ // File paths may contain a trailing slash
if strings.Contains(path, "?") {
return uri
}
+ // Nothing else should contain a trailing slash
return strings.TrimSuffix(uri, "/")
}
More information about the lxc-devel
mailing list