From 5630d25d8fd1cc50238d9bf8cd6da4dede0d82c3 Mon Sep 17 00:00:00 2001 From: Shubham Tiwari Date: Mon, 18 Nov 2024 17:11:07 +0530 Subject: [PATCH 1/2] chore: pass query params in delete --- client/client.go | 2 +- client/request_handler.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/client/client.go b/client/client.go index 131003b37..2072fee98 100644 --- a/client/client.go +++ b/client/client.go @@ -145,7 +145,7 @@ func (c *Client) SendRequest(method string, rawURL string, data url.Values, // are added as information in the url itself. Also while Content-Type is json, we are sending // json body. In that case, data variable contains all other parameters than body, which is the //same case as GET method. In that case as well all parameters will be added to url - if method == http.MethodGet || contentType == jsonContentType { + if method == http.MethodGet || method == http.MethodDelete || contentType == jsonContentType { if data != nil { v, _ := form.EncodeToStringWith(data, delimiter, escapee, keepZeros) s := delimitingRegex.ReplaceAllString(v, "") diff --git a/client/request_handler.go b/client/request_handler.go index e1393823e..039c4b881 100644 --- a/client/request_handler.go +++ b/client/request_handler.go @@ -94,6 +94,6 @@ func (c *RequestHandler) Get(path string, queryData url.Values, headers map[stri return c.sendRequest(http.MethodGet, path, queryData, headers) } -func (c *RequestHandler) Delete(path string, nothing url.Values, headers map[string]interface{}) (*http.Response, error) { - return c.sendRequest(http.MethodDelete, path, nil, headers) +func (c *RequestHandler) Delete(path string, queryData url.Values, headers map[string]interface{}) (*http.Response, error) { + return c.sendRequest(http.MethodDelete, path, queryData, headers) } From ff519a2b9b408e54e9c964ad884bb9d6c87365f6 Mon Sep 17 00:00:00 2001 From: Shubham Tiwari Date: Mon, 2 Dec 2024 19:33:58 +0530 Subject: [PATCH 2/2] chore: process query params for put also --- client/client.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/client/client.go b/client/client.go index 2072fee98..e1cab41de 100644 --- a/client/client.go +++ b/client/client.go @@ -164,13 +164,9 @@ func (c *Client) SendRequest(method string, rawURL string, data url.Values, } else { //Here the HTTP POST methods which is not having json content type are processed //All the values will be added in data and encoded (all body, query, path parameters) - if method == http.MethodPost { + if method == http.MethodPost || method == http.MethodPut { valueReader = strings.NewReader(data.Encode()) } - credErr := c.validateCredentials() - if credErr != nil { - return nil, credErr - } req, err = http.NewRequest(method, u.String(), valueReader) if err != nil { return nil, err @@ -178,6 +174,10 @@ func (c *Client) SendRequest(method string, rawURL string, data url.Values, } + credErr := c.validateCredentials() + if credErr != nil { + return nil, credErr + } req.SetBasicAuth(c.basicAuth()) // E.g. "User-Agent": "twilio-go/1.0.0 (darwin amd64) go/go1.17.8"