21217: Automatically clean double-slash in API URLs. 21217-invalid-auth-header
authorTom Clegg <tom@curii.com>
Fri, 1 Dec 2023 21:07:31 +0000 (16:07 -0500)
committerTom Clegg <tom@curii.com>
Fri, 1 Dec 2023 21:07:31 +0000 (16:07 -0500)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@curii.com>

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.