sendRequest issues a single POST through the proxy. It returns rather than asserting so callers can branch on whether the host is currently routed (MITM'd to aibridged) or not (tunneled, dial of an unresolvable host fails).
(t *testing.T, targetURL string)
| 199 | // routed (MITM'd to aibridged) or not (tunneled, dial of an unresolvable |
| 200 | // host fails). |
| 201 | func (h *reloadTestHarness) sendRequest(t *testing.T, targetURL string) requestResult { |
| 202 | t.Helper() |
| 203 | |
| 204 | ctx, cancel := context.WithTimeout(t.Context(), testutil.WaitShort) |
| 205 | defer cancel() |
| 206 | |
| 207 | req, err := http.NewRequestWithContext(ctx, http.MethodPost, targetURL, strings.NewReader(`{}`)) |
| 208 | require.NoError(t, err) |
| 209 | req.Header.Set("Content-Type", "application/json") |
| 210 | |
| 211 | resp, err := h.client.Do(req) |
| 212 | if err != nil { |
| 213 | return requestResult{err: err} |
| 214 | } |
| 215 | defer resp.Body.Close() |
| 216 | body, err := io.ReadAll(resp.Body) |
| 217 | require.NoError(t, err) |
| 218 | return requestResult{status: resp.StatusCode, body: string(body)} |
| 219 | } |
| 220 | |
| 221 | // expectRoutedTo asserts the proxy MITM'd the request and forwarded it |
| 222 | // to aibridged with the expected /api/v2/aibridge/<name>/<path>. |