fetch function

Future<FetchRequest> fetch(
  1. FetchOptions options, {
  2. HttpxClient? httpxClient,
  3. bool close = false,
})

Implementation

Future<FetchRequest> fetch(
  FetchOptions options, {
  HttpxClient? httpxClient,
  bool close = false,
}) async {
  final client = httpxClient ?? FetchGlobals().defaultHttpxClient;

  final clientRequest = client.createRequest(
    uri: options.url,
    method: options.method,
    headers: options.headers,
    realmsCredentials: options.realmsCredentials,
    maxRedirects: options.maxRedirects,
    connectionTimeout: options.connectionTimeout,
    cachePolicy: options.cachePolicy,
  );

  final request = FetchRequestImpl(clientRequest, options: options);

  if (close) {
    await request.close();
  }

  return request;
}