copyWithAuthorization method

HttpRequest copyWithAuthorization(
  1. HttpClient client, [
  2. Authorization? authorization
])

Copies this instance with a different client and authorization if provided.

If authorization is null returns this.

Implementation

HttpRequest copyWithAuthorization(HttpClient client,
    [Authorization? authorization]) {
  if (authorization == null || authorization == this.authorization) {
    return this;
  }

  var requestHeaders = client.clientRequester.buildRequestHeaders(
      client, method, url,
      headers: this.requestHeaders,
      authorization: authorization,
      contentType: headerContentType,
      accept: headerAccept);

  var queryParameters = this.queryParameters != null
      ? Map<String, String?>.from(this.queryParameters!)
      : null;

  var requestURL = client.clientRequester.buildRequestURL(client, url,
      authorization: authorization,
      queryParameters: queryParameters,
      noQueryString: noQueryString);

  var copy = HttpRequest(
    method,
    url,
    requestURL,
    queryParameters: queryParameters,
    noQueryString: noQueryString,
    authorization: authorization,
    withCredentials: withCredentials,
    responseType: responseType,
    mimeType: mimeType,
    requestHeaders: requestHeaders,
    sendData: sendData,
  );

  copy._retries = _retries;

  return copy;
}