getContentLength method

Future<int?> getContentLength(
  1. dynamic url, {
  2. Map<String, String> headers = const {},
  3. bool validate = true,
})

Implementation

Future<int?> getContentLength(
  dynamic url, {
  Map<String, String> headers = const {},
  bool validate = true,
}) async {
  final response = await head(url, headers: headers);
  if (_closed) throw HttpClientClosedException();

  if (validate) {
    _validateResponse(response, response.statusCode);
  }

  return int.tryParse(response.headers['content-length'] ?? '');
}