SigV4Request constructor

SigV4Request(
  1. AwsSigV4Client awsSigV4Client, {
  2. required String method,
  3. String? path,
  4. String? datetime,
  5. Map<String, String>? queryParams,
  6. Map<String, String?>? headers,
  7. String? authorizationHeader,
  8. dynamic body,
})

Implementation

SigV4Request(
  this.awsSigV4Client, {
  required String method,
  String? path,
  this.datetime,
  this.queryParams,
  this.headers,
  this.authorizationHeader,
  dynamic body,
}) {
  this.method = method.toUpperCase();
  this.path = '${awsSigV4Client.pathComponent}$path';
  headers =
      headers?.map((key, value) => MapEntry(key.toLowerCase(), value)) ?? {};

  if (headers!['content-type'] == null && this.method != 'GET') {
    headers!['content-type'] = awsSigV4Client.defaultContentType;
  }
  if (headers!['accept'] == null) {
    headers!['accept'] = awsSigV4Client.defaultAcceptType;
  }
  if (body == null || this.method == 'GET') {
    this.body = '';
  } else {
    this.body = json.encode(body);
  }
  if (body == '') {
    headers!.remove('content-type');
  }
  datetime = datetime ?? SigV4.generateDatetime();

  headers![_xAmzDate] = datetime;
  final endpointUri = Uri.parse(awsSigV4Client.endpoint);
  headers![_host] = endpointUri.host;

  headers![_authorization] =
      authorizationHeader ?? _generateAuthorization(datetime!);
  if (awsSigV4Client.sessionToken != null) {
    headers![_xAmzSecurityToken] = awsSigV4Client.sessionToken;
  }
  headers!.remove(_host);

  url = _generateUrl();
}