| 51 | } |
| 52 | |
| 53 | func (c *Client) Proxy(name string) (*Proxy, error) { |
| 54 | req, err := http.NewRequest("GET", c.endpoint+"/proxies/"+name, nil) |
| 55 | if err != nil { |
| 56 | return nil, fmt.Errorf("failed to make proxy request: %w", err) |
| 57 | } |
| 58 | resp, err := c.httpClient.Do(req) // #nosec G704 -- toxiproxy endpoint is controlled test infrastructure. |
| 59 | if err != nil { |
| 60 | return nil, fmt.Errorf("failed to http get proxy: %w", err) |
| 61 | } |
| 62 | defer resp.Body.Close() |
| 63 | |
| 64 | if resp.StatusCode != 200 { |
| 65 | body, _ := io.ReadAll(resp.Body) |
| 66 | return nil, fmt.Errorf("error getting proxy %s: %s %s", name, resp.Status, body) |
| 67 | } |
| 68 | |
| 69 | var p Proxy |
| 70 | if err := json.NewDecoder(resp.Body).Decode(&p); err != nil { |
| 71 | return nil, fmt.Errorf("error decoding json for proxy %s: %w", name, err) |
| 72 | } |
| 73 | p.client = c |
| 74 | |
| 75 | return &p, nil |
| 76 | } |
| 77 | |
| 78 | func (c *Client) ResetState() error { |
| 79 | req, err := http.NewRequest("POST", c.endpoint+"/reset", http.NoBody) |