toHttpClientResponse method
Implementation
Future<HttpClientResponse?> toHttpClientResponse([HttpClient? httpClient]) async {
if (!await _exists) {
return null;
}
HttpHeaders responseHeaders = createHttpHeaders(initialHeaders: _getResponseHeaders());
// Unless content-encoding specified, like gzip or delfate, the real size is decoded size.
// Trust the blob length.
if (responseHeaders.value(HttpHeaders.contentEncodingHeader) == null) {
int blobLength = await _blob.length;
if (contentLength != blobLength) {
contentLength = blobLength;
// Keep the exposed Content-Length header in sync with the actual blob length
responseHeaders.set(HttpHeaders.contentLengthHeader, blobLength);
}
}
// Touch lastUsed and persist on a throttle for on-disk LRU semantics
_touchLastUsedAndMaybePersist();
return HttpClientStreamResponse(
_blob.openRead(),
statusCode: HttpStatus.ok,
initialHeaders: responseHeaders,
)..compressionState = _getCompressionState(httpClient, responseHeaders);
}