canCompressResponse function

bool canCompressResponse(
  1. Response response, {
  2. int minLength = APIResponseCompression.defaultMinLength,
})

Returns true if response can be compressed: a status with a full body (not 1xx, 204, 206 or 304, and no Content-Range), no Content-Encoding, not an already compressed Content-Type, and not smaller than minLength. See canGzipEncodeResponse.

Implementation

bool canCompressResponse(
  Response response, {
  int minLength = APIResponseCompression.defaultMinLength,
}) {
  final statusCode = response.statusCode;
  if (statusCode < 200 ||
      statusCode == HttpStatus.noContent ||
      statusCode == HttpStatus.partialContent ||
      statusCode == HttpStatus.notModified) {
    return false;
  }

  // A range of the (uncompressed) representation:
  if (response.headers.containsKey(HttpHeaders.contentRangeHeader)) {
    return false;
  }

  return canGzipEncodeResponse(response, minimalGzipContentLength: minLength);
}