merge method

如果当前config的某项为null,则获取other里面的值, 并返回一个新的config

  • params 合并
  • header 合并
  • files 合并

Implementation

AjanuwHttpConfig merge(AjanuwHttpConfig other) {
  var r = AjanuwHttpConfig(
    url: url ?? other.url,
    method: method ?? other.method,
    body: body ?? other.body,
    params: params,
    headers: headers,
    timeout: timeout ?? other.timeout,
    encoding: encoding ?? other.encoding,
    onUploadProgress: onUploadProgress ?? other.onUploadProgress,
    onDownloadProgress: onDownloadProgress ?? other.onDownloadProgress,
    files: files,
    validateStatus: validateStatus ?? other.validateStatus,
    paramsSerializer: paramsSerializer ?? other.paramsSerializer,
    baseURL: baseURL ?? other.baseURL,
    responseType: responseType ?? other.responseType,
    close: close ?? other.close,
    interceptors: interceptors,
  );

  r.params ??= {};
  if (other.params?.isNotEmpty ?? false) {
    other.params!.forEach((key, value) => r.params![key] ??= value);
  }

  r.headers ??= {};
  if (other.headers?.isNotEmpty ?? false) {
    other.headers!.forEach((key, value) => r.headers![key] ??= value);
  }

  r.files ??= [];
  if (other.files?.isNotEmpty ?? false) {
    r.files!.addAll(other.files!);
  }

  r.interceptors ??= [];
  if (other.interceptors?.isNotEmpty ?? false) {
    r.interceptors!.addAll(other.interceptors!);
  }

  return r;
}