proxyHttp method

Future<HttpProxyResponse> proxyHttp({
  1. required String method,
  2. required String url,
  3. Map<String, String> headers = const {},
  4. String body = '',
  5. HttpProxyCredentialMode credentialMode = HttpProxyCredentialMode.none,
  6. String? provider,
})

Asks the Hub to perform an outbound AI HTTPS request on the caller's behalf — used by the browser client, which cannot reach provider APIs directly (CORS). The Hub enforces an https + host allowlist and, when credentialMode is HttpProxyCredentialMode.hubDefault, injects its own key for provider; otherwise headers (with the caller's key) are forwarded verbatim. Completes with the provider's reply, or an HttpProxyResponse whose error is set on a rejected target / transport failure.

Implementation

Future<HttpProxyResponse> proxyHttp({
  required String method,
  required String url,
  Map<String, String> headers = const {},
  String body = '',
  HttpProxyCredentialMode credentialMode = HttpProxyCredentialMode.none,
  String? provider,
}) {
  _ensureConnected();
  final id = newId();
  final completer = Completer<HttpProxyResponse>();
  _pendingHttpProxies[id] = completer;
  _connection!.send(
    ControlFrame(
      HttpProxyRequest(
        requestId: id,
        method: method,
        url: url,
        headers: headers,
        body: body,
        credentialMode: credentialMode,
        provider: provider,
      ),
    ),
  );
  // Longer bound: this proxies an outbound AI/LLM call which can be slow.
  return _rpcTimeout(
    completer.future,
    () => _pendingHttpProxies.remove(id),
    timeout: const Duration(seconds: 120),
  );
}