Skip to content

Instantly share code, notes, and snippets.

@BinaryKitten
Last active June 8, 2024 08:33
Show Gist options
  • Save BinaryKitten/2f50ba3ef9e264dbab1342f51e5bebab to your computer and use it in GitHub Desktop.
Save BinaryKitten/2f50ba3ef9e264dbab1342f51e5bebab to your computer and use it in GitHub Desktop.
streamedPsrResponse Macro
<?php
declare(strict_types=1);
namespace App\Providers;
use Illuminate\Http\Client\Response as HttpClientResponse;
use Illuminate\Support\ServiceProvider;
use Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory;
use Symfony\Component\HttpFoundation\StreamedResponse;
class AppServiceProvider extends ServiceProvider
{
public function boot(): void
{
HttpClientResponse::macro('toStreamedPsrResponse', function (int $responseBufferMaxLength = 16372): StreamedResponse {
return resolve(HttpFoundationFactory::class, [$responseBufferMaxLength])
->createResponse($this->response, streamed: true);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment