internal: properly encode path in Client.NewRequest

This commit is contained in:
Simon Ser 2020-01-20 13:40:26 +01:00
parent d21315e9fc
commit 3e41eefd12
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48

View File

@ -75,11 +75,17 @@ func (c *Client) SetBasicAuth(username, password string) {
}
func (c *Client) NewRequest(method string, href string, body io.Reader) (*http.Request, error) {
hrefURL, err := url.Parse(href)
if err != nil {
return nil, fmt.Errorf("failed to parse request href %q: %v", href, err)
}
u := url.URL{
Scheme: c.endpoint.Scheme,
User: c.endpoint.User,
Host: c.endpoint.Host,
Path: path.Join(c.endpoint.Path, href),
Scheme: c.endpoint.Scheme,
User: c.endpoint.User,
Host: c.endpoint.Host,
Path: path.Join(c.endpoint.Path, hrefURL.Path),
RawQuery: hrefURL.RawQuery,
}
return http.NewRequest(method, u.String(), body)
}