Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8465ad4

Browse filesBrowse files
[HttpFoundation][FrameworkBundle] Add BinaryFileResponse::setXSendfileHeader() and corresponding config option to help configure upload acceleration
1 parent 4b817ea commit 8465ad4
Copy full SHA for 8465ad4

File tree

8 files changed

+25
-3
lines changed
Filter options

8 files changed

+25
-3
lines changed

‎src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ CHANGELOG
1313
* Enable `json_decode_detailed_errors` in the default serializer context in debug mode by default when `seld/jsonlint` is installed
1414
* Register `Symfony\Component\Serializer\NameConverter\SnakeCaseToCamelCaseNameConverter` as a service named `serializer.name_converter.snake_case_to_camel_case` if available
1515
* Add support for `SYMFONY_TRUSTED_PROXIES`, `SYMFONY_TRUSTED_HEADERS`, `SYMFONY_TRUST_X_SENDFILE_TYPE_HEADER` and `SYMFONY_TRUSTED_HOSTS` env vars
16+
* Add option `framework.x_sendfile_header` to configure the name of the header that should be used for file uploads acceleration, if any supported by the web-server
1617

1718
7.1
1819
---

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ public function getConfigTreeBuilder(): TreeBuilder
9292
->info('Set true to enable support for xsendfile in binary file responses.')
9393
->defaultValue('%env(bool:default::SYMFONY_TRUST_X_SENDFILE_TYPE_HEADER)%')
9494
->end()
95+
->scalarNode('x_sendfile_header')
96+
->info('The name of the header that should be used for file uploads acceleration, if any supported by the web-server.')
97+
->defaultValue('%env(default::SYMFONY_X_SENDFILE_HEADER)%')
98+
->end()
9599
->scalarNode('ide')->defaultValue($this->debug ? '%env(default::SYMFONY_IDE)%' : null)->end()
96100
->booleanNode('test')->end()
97101
->scalarNode('default_locale')->defaultValue('en')->end()

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ public function load(array $configs, ContainerBuilder $container): void
312312

313313
$container->setParameter('kernel.http_method_override', $config['http_method_override']);
314314
$container->setParameter('kernel.trust_x_sendfile_type_header', $config['trust_x_sendfile_type_header']);
315+
$container->setParameter('kernel.x_sendfile_header', $config['x_sendfile_header']);
315316
$container->setParameter('kernel.trusted_hosts', [0] === array_keys($config['trusted_hosts']) ? $config['trusted_hosts'][0] : $config['trusted_hosts']);
316317
$container->setParameter('kernel.default_locale', $config['default_locale']);
317318
$container->setParameter('kernel.enabled_locales', $config['enabled_locales']);

‎src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ public function boot(): void
106106
if ($this->container->hasParameter('kernel.trust_x_sendfile_type_header') && $this->container->getParameter('kernel.trust_x_sendfile_type_header')) {
107107
BinaryFileResponse::trustXSendfileTypeHeader();
108108
}
109+
110+
if ($this->container->hasParameter('kernel.x_sendfile_header') && $header = $this->container->getParameter('kernel.x_sendfile_header')) {
111+
BinaryFileResponse::setXSendfileHeader($header);
112+
}
109113
}
110114

111115
public function build(ContainerBuilder $container): void

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,7 @@ protected static function getBundleDefaultConfig()
705705
'http_method_override' => false,
706706
'handle_all_throwables' => true,
707707
'trust_x_sendfile_type_header' => '%env(bool:default::SYMFONY_TRUST_X_SENDFILE_TYPE_HEADER)%',
708+
'x_sendfile_header' => '%env(default::SYMFONY_X_SENDFILE_HEADER)%',
708709
'ide' => '%env(default::SYMFONY_IDE)%',
709710
'default_locale' => 'en',
710711
'enabled_locales' => [],

‎src/Symfony/Bundle/FrameworkBundle/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/composer.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"symfony/deprecation-contracts": "^2.5|^3",
2626
"symfony/error-handler": "^6.4|^7.0",
2727
"symfony/event-dispatcher": "^6.4|^7.0",
28-
"symfony/http-foundation": "^6.4|^7.0",
28+
"symfony/http-foundation": "^7.2",
2929
"symfony/http-kernel": "^7.2",
3030
"symfony/polyfill-mbstring": "~1.0",
3131
"symfony/filesystem": "^7.1",

‎src/Symfony/Component/HttpFoundation/BinaryFileResponse.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/BinaryFileResponse.php
+12-2Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
class BinaryFileResponse extends Response
2727
{
2828
protected static bool $trustXSendfileTypeHeader = false;
29+
protected static ?string $xSendfileHeader = null;
2930

3031
protected File $file;
3132
protected ?\SplTempFileObject $tempFileObject = null;
@@ -208,9 +209,10 @@ public function prepare(Request $request): static
208209
$this->headers->set('Accept-Ranges', $request->isMethodSafe() ? 'bytes' : 'none');
209210
}
210211

211-
if (self::$trustXSendfileTypeHeader && $request->headers->has('X-Sendfile-Type')) {
212+
$type = self::$trustXSendfileTypeHeader && $request->headers->has('X-Sendfile-Type') ? $request->headers->get('X-Sendfile-Type') : self::$xSendfileHeader;
213+
214+
if (null !== $type) {
212215
// Use X-Sendfile, do not send any content.
213-
$type = $request->headers->get('X-Sendfile-Type');
214216
$path = $this->file->getRealPath();
215217
// Fall back to scheme://path for stream wrapped locations.
216218
if (false === $path) {
@@ -370,6 +372,14 @@ public static function trustXSendfileTypeHeader(): void
370372
self::$trustXSendfileTypeHeader = true;
371373
}
372374

375+
/**
376+
* Trust X-Sendfile header and the likes.
377+
*/
378+
public static function setXSendfileHeader(string $name): void
379+
{
380+
self::$xSendfileHeader = $name;
381+
}
382+
373383
/**
374384
* If this is set to true, the file will be unlinked after the request is sent
375385
* Note: If the X-Sendfile header is used, the deleteFileAfterSend setting will not be used.

‎src/Symfony/Component/HttpFoundation/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ CHANGELOG
77
* Add optional `$requests` parameter to `RequestStack::__construct()`
88
* Add optional `$v4Bytes` and `$v6Bytes` parameters to `IpUtils::anonymize()`
99
* Add `PRIVATE_SUBNETS` as a shortcut for private IP address ranges to `Request::setTrustedProxies()`
10+
* Add `BinaryFileResponse::setXSendfileHeader()`
1011

1112
7.1
1213
---

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.