Skip to content

Commit

Permalink
fix(client): fix bug of query cache (#381)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pengfei Xue committed Dec 23, 2020
1 parent 24fba00 commit ab64a0c
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions rest/rest.go
Expand Up @@ -68,6 +68,15 @@ type parsedURL struct {
queries map[string][]string
}

func (u *parsedURL) deepCopyQueries() map[string][]string {
queries := make(map[string][]string)
for k, v := range u.queries {
queries[k] = make([]string, len(v))
copy(queries[k], v)
}
return queries
}

// Client implements builder pattern for http client.
type Client struct {
endpoint string
Expand Down Expand Up @@ -142,16 +151,22 @@ func (c *Client) parseURL(rawurl string) (parsedURL, error) {
// Request creates an request with specific method and url path.
// The code is only for checking if status code of response is right.
func (c *Client) Request(method string, code int, url string) *Request {
var path *path
queries := make(map[string][]string)
parsedURL, err := c.parseURL(url)
if err == nil {
path = parsedURL.path
queries = parsedURL.deepCopyQueries()
}
req := &Request{
err: err,
method: method,
code: code,
endpoint: c.endpoint,
path: parsedURL.path,
path: path,
client: c.config.Executor,
paths: map[string]string{},
queries: parsedURL.queries,
queries: queries,
headers: map[string][]string{},
forms: map[string][]string{},
files: map[string]interface{}{},
Expand Down

0 comments on commit ab64a0c

Please sign in to comment.