sendRaw method

Future<StreamedResponse> sendRaw({
  1. required String method,
  2. required String requestUri,
  3. required Map<String, AwsExceptionFn> exceptionFnMap,
  4. bool signed = true,
  5. Map<String, List<String>>? queryParams,
  6. Map<String, String>? headers,
  7. dynamic payload,
})

Implementation

Future<StreamedResponse> sendRaw({
  required String method,
  required String requestUri,
  required Map<String, AwsExceptionFn> exceptionFnMap,
  bool signed = true,
  Map<String, List<String>>? queryParams,
  Map<String, String>? headers,
  dynamic payload,
}) async {
  var uri = Uri.parse('${_endpoint.url}$requestUri');
  uri = uri.replace(queryParameters: {
    ...uri.queryParametersAll,
    ...?queryParams,
  });
  final rq = Request(
    method,
    uri,
  );
  if (payload != null) {
    if (payload is List<int>) {
      rq.bodyBytes = payload;
    } else if (payload is String) {
      rq.body = payload;
    } else {
      rq.body = json.encode(payload);
    }
  }
  rq.headers['accept'] = 'application/json';
  if (headers != null) {
    rq.headers.addAll(headers);
  }

  if (signed) {
    final credentials = await _credentialsProvider?.call(client: _client);

    if (credentials == null) {
      throw Exception('credentials for signing request is null');
    }

    _requestSigner(
      rq: rq,
      service: _endpoint.service,
      region: _endpoint.signingRegion,
      credentials: credentials,
    );
  }

  final rs = await _client.send(rq);

  if (rs.statusCode < 200 || rs.statusCode >= 300) {
    throwException(rs, await rs.stream.bytesToString(), exceptionFnMap);
  }

  return rs;
}