sendUnstreamed method

Future<Response> sendUnstreamed(
  1. String method,
  2. dynamic url,
  3. Map<String, String>? headers,
  4. [dynamic body,
  5. Encoding? encoding]
)

Sends a non-streaming Request and returns a non-streaming Response.

Implementation

Future<http.Response> sendUnstreamed(
    String method, url, Map<String, String>? headers,
    [body, Encoding? encoding]) async {
  var request =
      http.Request(method, url is Uri ? url : Uri.parse(url.toString()));

  if (headers != null) request.headers.addAll(headers);

  if (encoding != null) request.encoding = encoding;
  if (body != null) {
    if (body is String) {
      request.body = body;
    } else if (body is List<int>) {
      request.bodyBytes = List<int>.from(body);
    } else if (body is Map<String, dynamic>) {
      request.bodyFields =
          body.map((k, v) => MapEntry(k, v is String ? v : v.toString()));
    } else {
      _log.severe('Body is not a String, List<int>, or Map<String, String>');
      throw ArgumentError.value(body, 'body',
          'must be a String, List<int>, or Map<String, String>.');
    }
  }

  return http.Response.fromStream(await send(request));
}