Configure sends configuration to the proxy.
(filePath, workDir string)
| 139 | |
| 140 | // Configure sends configuration to the proxy. |
| 141 | func (p *CapiProxy) Configure(filePath, workDir string) error { |
| 142 | p.mu.Lock() |
| 143 | url := p.proxyURL |
| 144 | p.mu.Unlock() |
| 145 | |
| 146 | if url == "" { |
| 147 | return fmt.Errorf("proxy not started") |
| 148 | } |
| 149 | |
| 150 | config := fmt.Sprintf(`{"filePath":%q,"workDir":%q}`, filePath, workDir) |
| 151 | resp, err := http.Post(url+"/config", "application/json", strings.NewReader(config)) |
| 152 | if err != nil { |
| 153 | return fmt.Errorf("failed to configure proxy: %w", err) |
| 154 | } |
| 155 | defer resp.Body.Close() |
| 156 | |
| 157 | if resp.StatusCode != 200 { |
| 158 | return fmt.Errorf("proxy config failed with status %d", resp.StatusCode) |
| 159 | } |
| 160 | |
| 161 | return nil |
| 162 | } |
| 163 | |
| 164 | // GetExchanges retrieves the captured HTTP exchanges from the proxy. |
| 165 | func (p *CapiProxy) GetExchanges() ([]ParsedHttpExchange, error) { |