diff --git a/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php b/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php index 69afbe1c84..d20880fceb 100644 --- a/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php +++ b/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php @@ -192,6 +192,10 @@ class BinaryFileResponse extends Response // Use X-Sendfile, do not send any content. $type = $request->headers->get('X-Sendfile-Type'); $path = $this->file->getRealPath(); + // Fall back to scheme://path for stream wrapped locations. + if (false === $path) { + $path = $this->file->getPathname(); + } if (strtolower($type) == 'x-accel-redirect') { // Do X-Accel-Mapping substitutions. // @link http://wiki.nginx.org/X-accel#X-Accel-Redirect diff --git a/src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php b/src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php index e4f05fadcf..35dfab5366 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php @@ -153,13 +153,16 @@ class BinaryFileResponseTest extends ResponseTestCase ); } - public function testXSendfile() + /** + * @dataProvider provideXSendfileFiles + */ + public function testXSendfile($file) { $request = Request::create('/'); $request->headers->set('X-Sendfile-Type', 'X-Sendfile'); BinaryFileResponse::trustXSendfileTypeHeader(); - $response = BinaryFileResponse::create(__DIR__.'/../README.md', 200, array('Content-Type' => 'application/octet-stream')); + $response = BinaryFileResponse::create($file, 200, array('Content-Type' => 'application/octet-stream')); $response->prepare($request); $this->expectOutputString(''); @@ -168,6 +171,14 @@ class BinaryFileResponseTest extends ResponseTestCase $this->assertContains('README.md', $response->headers->get('X-Sendfile')); } + public function provideXSendfileFiles() + { + return array( + array(__DIR__.'/../README.md'), + array('file://'.__DIR__.'/../README.md'), + ); + } + /** * @dataProvider getSampleXAccelMappings */