Skip to content

Commit e3629d2

Browse files
alexander-schranzfabpot
authored andcommitted
[FrameworkBundle] Add support to set BinaryFileResponse::trustXSendfileTypeHeader over config
1 parent 0112280 commit e3629d2

File tree

10 files changed

+23
-1
lines changed

10 files changed

+23
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ CHANGELOG
99
* Add `cache:pool:invalidate-tags` command
1010
* Add `xliff` support in addition to `xlf` for `XliffFileDumper`
1111
* Deprecate the `reset_on_message` config option. It can be set to `true` only and does nothing now
12+
* Add `trust_x_sendfile_type_header` option
1213

1314
6.0
1415
---

DependencyInjection/Configuration.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ public function getConfigTreeBuilder(): TreeBuilder
8181
->info("Set true to enable support for the '_method' request parameter to determine the intended HTTP method on POST requests. Note: When using the HttpCache, you need to call the method in your front controller instead")
8282
->defaultTrue()
8383
->end()
84+
->scalarNode('trust_x_sendfile_type_header')
85+
->info('Set true to enable support for xsendfile in binary file responses.')
86+
->defaultFalse()
87+
->end()
8488
->scalarNode('ide')->defaultValue('%env(default::SYMFONY_IDE)%')->end()
8589
->booleanNode('test')->end()
8690
->scalarNode('default_locale')->defaultValue('en')->end()

DependencyInjection/FrameworkExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ public function load(array $configs, ContainerBuilder $container)
330330
}
331331

332332
$container->setParameter('kernel.http_method_override', $config['http_method_override']);
333+
$container->setParameter('kernel.trust_x_sendfile_type_header', $config['trust_x_sendfile_type_header']);
333334
$container->setParameter('kernel.trusted_hosts', $config['trusted_hosts']);
334335
$container->setParameter('kernel.default_locale', $config['default_locale']);
335336
$container->setParameter('kernel.enabled_locales', $config['enabled_locales']);

FrameworkBundle.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass;
4646
use Symfony\Component\Form\DependencyInjection\FormPass;
4747
use Symfony\Component\HttpClient\DependencyInjection\HttpClientPass;
48+
use Symfony\Component\HttpFoundation\BinaryFileResponse;
4849
use Symfony\Component\HttpFoundation\Request;
4950
use Symfony\Component\HttpKernel\Bundle\Bundle;
5051
use Symfony\Component\HttpKernel\DependencyInjection\ControllerArgumentValueResolverPass;
@@ -95,6 +96,10 @@ public function boot()
9596
if ($this->container->getParameter('kernel.http_method_override')) {
9697
Request::enableHttpMethodParameterOverride();
9798
}
99+
100+
if ($this->container->getParameter('kernel.trust_x_sendfile_type_header')) {
101+
BinaryFileResponse::trustXSendfileTypeHeader();
102+
}
98103
}
99104

100105
public function build(ContainerBuilder $container)

Resources/config/schema/symfony-1.0.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
</xsd:choice>
4343

4444
<xsd:attribute name="http-method-override" type="xsd:boolean" />
45+
<xsd:attribute name="trust-x-sendfile-type-header" type="xsd:boolean" />
4546
<xsd:attribute name="ide" type="xsd:string" />
4647
<xsd:attribute name="secret" type="xsd:string" />
4748
<xsd:attribute name="default-locale" type="xsd:string" />

Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ protected static function getBundleDefaultConfig()
369369
{
370370
return [
371371
'http_method_override' => true,
372+
'trust_x_sendfile_type_header' => false,
372373
'ide' => '%env(default::SYMFONY_IDE)%',
373374
'default_locale' => 'en',
374375
'enabled_locales' => [],

Tests/DependencyInjection/Fixtures/php/full.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
],
1212
],
1313
'http_method_override' => false,
14+
'trust_x_sendfile_type_header' => true,
1415
'esi' => [
1516
'enabled' => true,
1617
],

Tests/DependencyInjection/Fixtures/xml/full.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
77
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
88

9-
<framework:config secret="s3cr3t" ide="file%%link%%format" default-locale="fr" http-method-override="false">
9+
<framework:config secret="s3cr3t" ide="file%%link%%format" default-locale="fr" http-method-override="false" trust-x-sendfile-type-header="true">
1010
<framework:enabled-locale>fr</framework:enabled-locale>
1111
<framework:enabled-locale>en</framework:enabled-locale>
1212
<framework:csrf-protection />

Tests/DependencyInjection/Fixtures/yml/full.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ framework:
77
csrf_protection:
88
field_name: _csrf
99
http_method_override: false
10+
trust_x_sendfile_type_header: true
1011
esi:
1112
enabled: true
1213
ssi:

Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,13 @@ public function testHttpMethodOverride()
179179
$this->assertFalse($container->getParameter('kernel.http_method_override'));
180180
}
181181

182+
public function testTrustXSendfileTypeHeader()
183+
{
184+
$container = $this->createContainerFromFile('full');
185+
186+
$this->assertTrue($container->getParameter('kernel.trust_x_sendfile_type_header'));
187+
}
188+
182189
public function testEsi()
183190
{
184191
$container = $this->createContainerFromFile('full');

0 commit comments

Comments
 (0)