giggsey/psr7-stream-response
Build a Symfony Response from a PSR-7 Stream
Maintainers
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
Suggests
None
Provides
None
Conflicts
None
Replaces
None
MIT 3adb4e91c19ab1e53e3b48fc1b3776185b1d0aed
- Joshua Gigg <giggsey.woop@gmail.com>
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;
