8000 Add support to set trustxsendfilehader over framework configuration · symfony/symfony@daad2ae · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit daad2ae

Browse files
Add support to set trustxsendfilehader over framework configuration
1 parent 791ee7d commit daad2ae

File tree

6 files changed

+19
-0
lines changed

6 files changed

+19
-0
lines changed

src/Symfony/Bundle/FrameworkBundle/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()

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

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

329329
$container->setParameter('kernel.http_method_override', $config['http_method_override']);
330+
$container->setParameter('kernel.trust_x_sendfile_type_header', $config['trust_x_sendfile_type_header']);
330331
$container->setParameter('kernel.trusted_hosts', $config['trusted_hosts']);
331332
$container->setParameter('kernel.default_locale', $config['default_locale']);
332333
$container->setParameter('kernel.enabled_locales', $config['enabled_locales']);

src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

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

99104
public function build(ContainerBuilder $container)

src/Symfony/Bundle/FrameworkBundle/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' => [],

src/Symfony/Bundle/FrameworkBundle/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:

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

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

177+
public function testTrustXSendfileTypeHeader()
178+
{
179+
$container = $this->createContainerFromFile('full');
180+
181+
$this->assertTrue($container->getParameter('kernel.trust_x_sendfile_type_header'));
182+
}
183+
177184
public function testEsi()
178185
{
179186
$container = $this->createContainerFromFile('full');

0 commit comments

Comments
 (0)
0