compose method

RequestOptions compose(
  1. BaseOptions baseOpt,
  2. String path, {
  3. Object? data,
  4. Map<String, dynamic>? queryParameters,
  5. CancelToken? cancelToken,
  6. ProgressCallback? onSendProgress,
  7. ProgressCallback? onReceiveProgress,
  8. StackTrace? sourceStackTrace,
})

Merge a BaseOptions with the current Options and compose them into the RequestOptions.

Implementation

RequestOptions compose(
  BaseOptions baseOpt,
  String path, {
  Object? data,
  Map<String, dynamic>? queryParameters,
  CancelToken? cancelToken,
  ProgressCallback? onSendProgress,
  ProgressCallback? onReceiveProgress,
  StackTrace? sourceStackTrace,
}) {
  if (data != null && kIsWeb) {
    if (sendTimeout != null && sendTimeout! > Duration.zero) {
      warningLog(
        'sendTimeout cannot be used without a request body to send on Web',
        StackTrace.current,
      );
    }
    if (onSendProgress != null) {
      warningLog(
        'onSendProgress cannot be used without a request body to send on Web',
        StackTrace.current,
      );
    }
  }
  final query = <String, dynamic>{};
  query.addAll(baseOpt.queryParameters);
  if (queryParameters != null) {
    query.addAll(queryParameters);
  }

  final headers = caseInsensitiveKeyMap(baseOpt.headers);
  if (this.headers != null) {
    headers.addAll(this.headers!);
  }
  if (this.contentType != null) {
    headers[Headers.contentTypeHeader] = this.contentType;
  }
  final String? contentType = headers[Headers.contentTypeHeader];
  final extra = Map<String, dynamic>.from(baseOpt.extra);
  if (this.extra != null) {
    extra.addAll(this.extra!);
  }
  final method = (this.method ?? baseOpt.method).toUpperCase();
  final requestOptions = RequestOptions(
    method: method,
    headers: headers,
    extra: extra,
    baseUrl: baseOpt.baseUrl,
    path: path,
    data: data,
    preserveHeaderCase: preserveHeaderCase ?? baseOpt.preserveHeaderCase,
    sourceStackTrace: sourceStackTrace ?? StackTrace.current,
    connectTimeout: baseOpt.connectTimeout,
    sendTimeout: sendTimeout ?? baseOpt.sendTimeout,
    receiveTimeout: receiveTimeout ?? baseOpt.receiveTimeout,
    responseType: responseType ?? baseOpt.responseType,
    validateStatus: validateStatus ?? baseOpt.validateStatus,
    receiveDataWhenStatusError:
        receiveDataWhenStatusError ?? baseOpt.receiveDataWhenStatusError,
    followRedirects: followRedirects ?? baseOpt.followRedirects,
    maxRedirects: maxRedirects ?? baseOpt.maxRedirects,
    persistentConnection:
        persistentConnection ?? baseOpt.persistentConnection,
    queryParameters: query,
    requestEncoder: requestEncoder ?? baseOpt.requestEncoder,
    responseDecoder: responseDecoder ?? baseOpt.responseDecoder,
    listFormat: listFormat ?? baseOpt.listFormat,
    onReceiveProgress: onReceiveProgress,
    onSendProgress: onSendProgress,
    cancelToken: cancelToken,
    contentType: contentType ?? this.contentType ?? baseOpt.contentType,
  );
  requestOptions.cancelToken?.requestOptions = requestOptions;
  return requestOptions;
}