Skip to content

Commit

Permalink
update r.QueryParam isntead of creating new variable
Browse files Browse the repository at this point in the history
  • Loading branch information
SVilgelm committed Oct 2, 2023
1 parent 97bab2e commit 73e6f07
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions middleware.go
Expand Up @@ -132,30 +132,25 @@ func parseRequestURL(c *Client, r *Request) error {
}

// Adding Query Param
if l := len(c.QueryParam) + len(r.QueryParam); l > 0 {
query := make(url.Values, l)
for k, v := range r.QueryParam {
query[k] = v[:]
}

if len(c.QueryParam)+len(r.QueryParam) > 0 {
for k, v := range c.QueryParam {
// skip query parameter if it was set from request
if _, ok := query[k]; ok {
// skip query parameter if it was set in request
if _, ok := r.QueryParam[k]; ok {
continue
}

query[k] = v[:]
r.QueryParam[k] = v[:]
}

// GitHub #123 Preserve query string order partially.
// Since not feasible in `SetQuery*` resty methods, because
// standard package `url.Encode(...)` sorts the query params
// alphabetically
if len(query) > 0 {
if len(r.QueryParam) > 0 {
if IsStringEmpty(reqURL.RawQuery) {
reqURL.RawQuery = query.Encode()
reqURL.RawQuery = r.QueryParam.Encode()
} else {
reqURL.RawQuery = reqURL.RawQuery + "&" + query.Encode()
reqURL.RawQuery = reqURL.RawQuery + "&" + r.QueryParam.Encode()
}
}
}
Expand Down

0 comments on commit 73e6f07

Please sign in to comment.