getCombinedHeaders method

Map<String, String> getCombinedHeaders(
  1. Map<String, String>? requestHeaders
)

merges custom request headers into the the headers here and returns a combined map of headers, where custom headers override default ones

Implementation

Map<String, String> getCombinedHeaders(Map<String, String>? requestHeaders) {
  final headerObj = headers ?? {};

  // if no request headers -> just return default headers
  if (requestHeaders == null || requestHeaders.isEmpty) {
    return headerObj;
  }

  // create a new map for that
  Map<String, String> retMap = {};

  // otherwise return a combination of both
  retMap.addAll(headerObj);
  retMap.addAll(requestHeaders);

  return retMap;
}