Skip to content

Commit

Permalink
Stream request
Browse files Browse the repository at this point in the history
  • Loading branch information
phenaproxima committed Jul 19, 2024
1 parent 2599862 commit ca45542
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ public function __construct(
*/
public function load(string $locator, int $maxBytes): PromiseInterface
{
$options = [];
$options = [
// @see https://docs.guzzlephp.org/en/stable/request-options.html#stream
RequestOptions::STREAM => true,
];
// Try to enforce the maximum download size during transport. This will only have an effect
// if cURL is in use.
// @see https://docs.guzzlephp.org/en/stable/request-options.html#progress
$options[RequestOptions::PROGRESS] = function (int $expectedBytes, int $bytesSoFar) use ($locator, $maxBytes): void
{
// Add 1 to $maxBytes to work around a bug in Composer.
Expand All @@ -43,6 +47,7 @@ public function load(string $locator, int $maxBytes): PromiseInterface
}
};
// Always send a X-PHP-TUF header with version information.
// @see https://docs.guzzlephp.org/en/stable/request-options.html#headers
$options[RequestOptions::HEADERS]['X-PHP-TUF'] = self::versionHeader();

// The name of the file in persistent storage will differ from $locator.
Expand All @@ -52,6 +57,7 @@ public function load(string $locator, int $maxBytes): PromiseInterface
$modifiedTime = $this->storage->getModifiedTime($name);
if ($modifiedTime) {
// @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Modified-Since.
// @see https://docs.guzzlephp.org/en/stable/request-options.html#headers
$options[RequestOptions::HEADERS]['If-Modified-Since'] = $modifiedTime->format('D, d M Y H:i:s') . ' GMT';
}

Expand Down

0 comments on commit ca45542

Please sign in to comment.