send method

  1. @override
Future<HttpResponse> send(
  1. HttpRequest request
)
override

Sends request.

Implementation

@override
Future<HttpResponse> send(HttpRequest request) async {
  if (_closed) {
    throw const ConfigurationException('the transport is closed');
  }
  HttpClientRequest? pending;
  try {
    return await _send(request, (open) => pending = open).timeout(_timeout);
  } on TimeoutException catch (e) {
    // Future.timeout only stops waiting. Without abort() the connection stays
    // open until the server answers, so a long-lived client leaks one socket
    // per timed-out request.
    pending?.abort();
    throw TransportException('the request timed out', cause: e);
  } on SocketException catch (e) {
    throw TransportException('could not reach the API', cause: e);
  } on HttpException catch (e) {
    throw TransportException('the connection failed', cause: e);
  } on TlsException catch (e) {
    throw TransportException('the TLS handshake failed', cause: e);
  } on ArgumentError catch (e) {
    // openUrl rejects a URL with no scheme or host — a base URL read from an
    // env var is the reachable case. A configuration fault, and it must not
    // leave here as a raw ArgumentError outside the sealed tree.
    throw ConfigurationException('the API URL is not usable: ${e.message}');
  }
}