toHttpRequest function

Future<Request> toHttpRequest (
  1. dynamic body,
  2. String method,
  3. Uri uri,
  4. Map<String, String> headers
)

Implementation

Future<http.Request> toHttpRequest(
  body,
  String method,
  Uri uri,
  Map<String, String> headers,
) async {
  final baseRequest = http.Request(method, uri);
  baseRequest.headers.addAll(headers);

  if (body != null) {
    if (body is String) {
      baseRequest.body = body;
    } else if (body is List<int>) {
      baseRequest.bodyBytes = body;
    } else if (body is Map<String, String>) {
      baseRequest.bodyFields = body;
    } else {
      throw ArgumentError.value('$body', 'body');
    }
  }
  return baseRequest;
}