diff --git a/api/api.go b/api/api.go index 48e4bdf5b..e1bb8e520 100644 --- a/api/api.go +++ b/api/api.go @@ -195,13 +195,14 @@ func (r *request) toHTTP() (*http.Request, error) { // newRequest is used to create a new request func (c *Client) newRequest(method, path string) *request { base, _ := url.Parse(c.config.URL) + u, _ := url.Parse(path) r := &request{ config: &c.config, method: method, url: &url.URL{ Scheme: base.Scheme, Host: base.Host, - Path: path, + Path: u.Path, }, params: make(map[string][]string), } @@ -211,6 +212,14 @@ func (c *Client) newRequest(method, path string) *request { if c.config.WaitTime != 0 { r.params.Set("wait", durToMsec(r.config.WaitTime)) } + + // Add in the query parameters, if any + for key, values := range u.Query() { + for _, value := range values { + r.params.Add(key, value) + } + } + return r } diff --git a/api/api_test.go b/api/api_test.go index 49d277553..e9114cf31 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -155,3 +155,22 @@ func TestParseWriteMeta(t *testing.T) { t.Fatalf("Bad: %v", wm) } } + +func TestQueryString(t *testing.T) { + // TODO t.Parallel() + c, s := makeClient(t, nil, nil) + defer s.Stop() + + r := c.newRequest("PUT", "/v1/abc?foo=bar&baz=zip") + q := &WriteOptions{Region: "foo"} + r.setWriteOptions(q) + + req, err := r.toHTTP() + if err != nil { + t.Fatalf("err: %s", err) + } + + if uri := req.URL.RequestURI(); uri != "/v1/abc?baz=zip&foo=bar®ion=foo" { + t.Fatalf("bad uri: %q", uri) + } +}