diff --git a/Factory/PsrHttpFactory.php b/Factory/PsrHttpFactory.php index 80ec527..fcb80d6 100644 --- a/Factory/PsrHttpFactory.php +++ b/Factory/PsrHttpFactory.php @@ -127,13 +127,13 @@ public function createResponse(Response $symfonyResponse) { $response = $this->responseFactory->createResponse($symfonyResponse->getStatusCode(), Response::$statusTexts[$symfonyResponse->getStatusCode()] ?? ''); - if ($symfonyResponse instanceof BinaryFileResponse) { + if ($symfonyResponse instanceof BinaryFileResponse && !$symfonyResponse->headers->has('Content-Range')) { $stream = $this->streamFactory->createStreamFromFile( $symfonyResponse->getFile()->getPathname() ); } else { $stream = $this->streamFactory->createStreamFromFile('php://temp', 'wb+'); - if ($symfonyResponse instanceof StreamedResponse) { + if ($symfonyResponse instanceof StreamedResponse || $symfonyResponse instanceof BinaryFileResponse) { ob_start(function ($buffer) use ($stream) { $stream->write($buffer); diff --git a/Tests/Factory/AbstractHttpMessageFactoryTest.php b/Tests/Factory/AbstractHttpMessageFactoryTest.php index 998edcc..d43f7fb 100644 --- a/Tests/Factory/AbstractHttpMessageFactoryTest.php +++ b/Tests/Factory/AbstractHttpMessageFactoryTest.php @@ -182,6 +182,23 @@ public function testCreateResponseFromBinaryFile() $this->assertEquals('Binary', $psrResponse->getBody()->__toString()); } + public function testCreateResponseFromBinaryFileWithRange() + { + $path = tempnam($this->tmpDir, uniqid()); + file_put_contents($path, 'Binary'); + + $request = new Request(); + $request->headers->set('Range', 'bytes=1-4'); + + $response = new BinaryFileResponse($path, 200, ['Content-Type' => 'plain/text']); + $response->prepare($request); + + $psrResponse = $this->factory->createResponse($response); + + $this->assertEquals('inar', $psrResponse->getBody()->__toString()); + $this->assertSame('bytes 1-4/6', $psrResponse->getHeaderLine('Content-Range')); + } + public function testUploadErrNoFile() { $file = new UploadedFile('', '', null, UPLOAD_ERR_NO_FILE, true);
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: