bug #16971 [HttpFoundation] Added the ability of using BinaryFileResponse with stream wrappers (jakzal, Sander-Toonen)
This PR was merged into the 2.3 branch. Discussion ---------- [HttpFoundation] Added the ability of using BinaryFileResponse with stream wrappers | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #12990 #13187 | License | MIT | Doc PR | ~ Commits -------1da3d61
[HttpFoundation] Added the ability of mapping stream wrapper protocols when using X-Sendfiledd129b7
[HttpFoundation] Add a test case for using BinaryFileResponse with stream wrappers
This commit is contained in:
commit
6b13708ab6
@ -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
|
||||
|
@ -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
|
||||
*/
|
||||
|
Reference in New Issue
Block a user