21217: Automatically clean double-slash in API URLs.
[arvados.git] / sdk / go / arvados / client.go
index eab61075e6e8718d0c3458dbec1508a8608b9251..c2f6361334d851a259fff3a467d6f4ae13b86ba0 100644 (file)
@@ -633,7 +633,11 @@ func (c *Client) apiURL(path string) string {
        if scheme == "" {
                scheme = "https"
        }
-       return scheme + "://" + c.APIHost + "/" + path
+       // Double-slash in URLs tend to cause subtle hidden problems
+       // (e.g., they can behave differently when a load balancer is
+       // in the picture). Here we ensure exactly one "/" regardless
+       // of whether the given APIHost or path has a superfluous one.
+       return scheme + "://" + strings.TrimSuffix(c.APIHost, "/") + "/" + strings.TrimPrefix(path, "/")
 }
 
 // DiscoveryDocument is the Arvados server's description of itself.