giggsey / psr7-stream-response
Build a Symfony Response from a PSR-7 Stream
1.2.0
2026-05-19 18:23 UTC
Requires
- php: >=8.2
- psr/http-message: ^1.1 || ^2.0
- symfony/http-foundation: ^6.4 || ^7.0 || ^8.0
Requires (Dev)
- guzzlehttp/psr7: ^2.6
- pestphp/pest: ^3.8
- phpunit/phpunit: ^11.0
This package is auto-updated.
Last update: 2026-05-19 18:24:24 UTC
README
Why?
Symfony's BinaryFileResponse allows presenting files to download to HTTP Clients. However, this expects full file paths. Some projects may want to stream a PSR-7 Stream to the client instead.
How to use
Instead of returning a BinaryFileResponse, create a PSR7StreamResponse, and return that.
Before
$response = new BinaryFileResponse($filePath); $response = $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, 'my-file.mp3'); return $response;
After
$response = new PSR7StreamResponse($stream, 'audio/mpeg'); $response = $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, 'my-file.mp3'); return $response;