Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(sdk-go): keep a Do path query string when adding query values
Yudhi Armyndharise0aacb4d8240
diff --git a/sdk/go/client.go b/sdk/go/client.goindex 4d24ae11c..fc4989449 100644--- a/sdk/go/client.go+++ b/sdk/go/client.go@@ -259,7 +259,11 @@ func (c *Client) doRaw(ctx context.Context, method, path string, query url.ValuerawURL := c.baseURL + pathif len(query) > 0 {- rawURL += "?" + query.Encode()+ sep := "?"+ if strings.Contains(path, "?") {+ sep = "&"+ }+ rawURL += sep + query.Encode()}req, err := http.NewRequestWithContext(ctx, method, rawURL, reader)diff --git a/sdk/go/client_test.go b/sdk/go/client_test.goindex 9d97b007a..8ff66398d 100644--- a/sdk/go/client_test.go+++ b/sdk/go/client_test.go@@ -9,6 +9,7 @@ import ("io""net/http""net/http/httptest"+ "net/url""strings""sync/atomic""testing"@@ -1734,3 +1735,16 @@ func TestRequestLogRedactsBaseURLPassword(t *testing.T) {t.Errorf("retry log = %q, want the retry logged without the password", got)}}++// A Do path that already carries a query string keeps it; the query values are appended with "&"+// rather than a second "?", which the server would read as part of the first value.+func TestDoPathWithQueryAppendsQueryValues(t *testing.T) {+ rt := &recordTransport{status: 200, body: `[]`}+ c := newTestClient(t, rt)+ if err := c.Do(context.Background(), "GET", "/api/sessions?limit=5", url.Values{"name": {"x"}}, nil, nil); err != nil {+ t.Fatal(err)+ }+ if got := rt.lastReq.URL.RawQuery; got != "limit=5&name=x" {+ t.Errorf("query = %q, want %q", got, "limit=5&name=x")+ }+}