executeRawRequest method

Future<StreamedResponse> executeRawRequest(
  1. String method,
  2. Uri uri, {
  3. Map<String, String>? headers,
  4. Uint8List? body,
  5. Set<int>? validStatuses,
})
inherited

Executes a HTTP request against give full uri.

Implementation

Future<http.StreamedResponse> executeRawRequest(
  String method,
  Uri uri, {
  Map<String, String>? headers,
  Uint8List? body,
  Set<int>? validStatuses,
}) async {
  final request = http.Request(method, uri);

  if (baseHeaders != null) {
    request.headers.addAll(baseHeaders!);
  }

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

  if (body != null) {
    request.bodyBytes = body;
  }

  if (cookieJar != null) {
    final cookies = await cookieJar!.loadForRequest(uri);
    if (cookies.isNotEmpty) {
      request.headers['cookie'] = cookies.join('; ');
    }
  }

  final response = await httpClient.send(request);

  final cookieHeader = response.headersSplitValues['set-cookie'];
  if (cookieHeader != null && cookieJar != null) {
    final cookies = cookieHeader.map(Cookie.fromSetCookieValue).toList();
    await cookieJar!.saveFromResponse(uri, cookies);
  }

  if (validStatuses?.contains(response.statusCode) ?? true) {
    return response;
  } else {
    if (kDebugMode) {
      throw await DynamiteStatusCodeException.fromResponse(response);
    } else {
      throw DynamiteStatusCodeException(response.statusCode);
    }
  }
}