fetchRemoteFile method

Future<RemoteAssociationFile> fetchRemoteFile(
  1. Uri uri
)

Perform the actual GET request behind --remote.

Overridable in tests so the default run never depends on network access. Redirects are not followed: a redirect answers as a non-200 status, which is already an issue this doctor reports.

Implementation

Future<RemoteAssociationFile> fetchRemoteFile(Uri uri) async {
  final client = HttpClient();
  try {
    final request = await client.getUrl(uri);
    request.followRedirects = false;
    final response = await request.close();
    final body = await response.transform(utf8.decoder).join();
    return RemoteAssociationFile(
      statusCode: response.statusCode,
      contentType: response.headers.contentType?.mimeType,
      body: body,
    );
  } finally {
    client.close();
  }
}