From 8e357121fd4af8532f081675b4d539c76cc8aba1 Mon Sep 17 00:00:00 2001 From: Shubham Date: Wed, 11 Dec 2024 21:33:27 +0530 Subject: [PATCH] chore: pass query params in delete (#257) --- client/client.go | 12 ++++++------ client/request_handler.go | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/client/client.go b/client/client.go index 131003b37..e1cab41de 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, "") @@ -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" 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) }