@@ -10,6 +10,7 @@ import (
10
10
"io"
11
11
"net/http"
12
12
"net/url"
13
+ "strings"
13
14
14
15
"github.com/go-log/log"
15
16
)
@@ -66,6 +67,13 @@ func New(cfg *Config) (c *Client, err error) {
66
67
return nil , fmt .Errorf ("unsupported protocol scheme %q" , baseURL .Scheme )
67
68
}
68
69
70
+ // If baseURL has a path component, ensure it is terminated with a separator, to prevent
71
+ // url.ResolveReference from stripping the final component of the path when constructing
72
+ // request URL.
73
+ if p := baseURL .Path ; p != "" && ! strings .HasSuffix (p , "/" ) {
74
+ baseURL .Path += "/"
75
+ }
76
+
69
77
c = & Client {
70
78
BaseURL : baseURL ,
71
79
AuthToken : cfg .AuthToken ,
@@ -87,10 +95,10 @@ func New(cfg *Config) (c *Client, err error) {
87
95
return c , nil
88
96
}
89
97
90
- // newRequest returns a new Request given a method, path, query, and optional body.
98
+ // newRequest returns a new Request given a method, relative path, query, and optional body.
91
99
func (c * Client ) newRequest (method , path string , body io.Reader ) (r * http.Request , err error ) {
92
100
u := c .BaseURL .ResolveReference (& url.URL {
93
- Path : path ,
101
+ Path : strings . TrimPrefix ( path , "/" ), // trim leading separator as path is relative.
94
102
})
95
103
96
104
r , err = http .NewRequest (method , u .String (), body )
0 commit comments