Skip to content

Commit

Permalink
Don't use cached size for file responses
Browse files Browse the repository at this point in the history
Fixes #7.
  • Loading branch information
kelunik committed Sep 14, 2018
1 parent 9c87daa commit 9f43db6
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/DocumentRoot.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,13 +380,18 @@ private function checkPreconditions(Request $request, int $mtime, string $etag):
private function doNonRangeResponse(Internal\FileInformation $fileInfo): \Generator
{
$headers = $this->makeCommonHeaders($fileInfo);
$headers["Content-Length"] = (string) $fileInfo->size;
$headers["Content-Type"] = $this->selectMimeTypeFromPath($fileInfo->path);

if (isset($fileInfo->buffer)) {
if ($fileInfo->buffer !== null) {
$headers["Content-Length"] = (string) $fileInfo->size;

return new Response(Status::OK, $headers, new InMemoryStream($fileInfo->buffer));
}

// Don't use cached size if we don't have buffered file contents,
// otherwise we get truncated files during development.
$headers["Content-Length"] = (string) $this->filesystem->size($fileInfo->path);

$handle = yield $this->filesystem->open($fileInfo->path, "r");

$response = new Response(Status::OK, $headers, $handle);
Expand Down

0 comments on commit 9f43db6

Please sign in to comment.