operationCallHeaders function

Map<String, String> operationCallHeaders(
  1. Operation operation,
  2. Map<String, Object?> params
)

The header parameters of one call, worked out once so every attempt of the call sends the same values: an operation that declares Idempotency-Key gets a fresh key when the caller gave none.

Implementation

Map<String, String> operationCallHeaders(Operation operation, Map<String, Object?> params) {
  final out = <String, String>{};
  for (final name in operation.headers) {
    if (protectedHeaders.contains(name.toLowerCase())) continue;
    final value = params[name];
    if (value != null && '$value'.isNotEmpty) {
      out[name] = '$value';
    } else if (name.toLowerCase() == 'idempotency-key') {
      out[name] = _uuid();
    }
  }
  return out;
}