request method

  1. @visibleForTesting
Future request(
  1. Uri uri, {
  2. HttpMethod method = HttpMethod.get,
  3. String? body,
  4. bool asJson = true,
})

Returns the decoded JSON.

Implementation

@visibleForTesting
Future<dynamic> request(Uri uri,
    {HttpMethod method: HttpMethod.get,
    String? body,
    bool asJson: true}) async {
  final headers = <String, String>{'PRIVATE-TOKEN': token};

  _log.fine('Making GitLab $method request to $uri.');

  final response = await _httpClient.request(uri, headers, method);

  if (!(response.statusCode >= 200 && response.statusCode < 300)) {
    throw new GitLabException(response.statusCode, response.body);
  }

  final contentType = response.headers["content-type"];
  final hasContentType = contentType != null;
  final hasCharset = contentType?.contains("charset") ?? false;
  if (assumeUtf8 && hasContentType && !hasCharset) {
    response.headers["content-type"] = "$contentType; charset=utf-8";
  }

  return asJson ? jsonDecode(response.body) : response.body;
}