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 730a472

Browse filesBrowse files
committed
bug #17757 [HttpFoundation] BinaryFileResponse sendContent return as parent. (2.3) (SpacePossum)
This PR was merged into the 2.3 branch. Discussion ---------- [HttpFoundation] BinaryFileResponse sendContent return as parent. (2.3) | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | License | MIT `BinaryFileResponse` extends `Response` and overrides the `sendContent`-method. It would be nice if it also returns as the parent does, i.e. itself. This makes it easier to deal with diff. `Response` classes. The other fixes are to make SCA easier. No BC-breaks AFAIK. Commits ------- 120dfe4 sendContent return as parent.
2 parents bb85161 + 120dfe4 commit 730a472
Copy full SHA for 730a472

File tree

1 file changed

+14
-9
lines changed
Filter options

1 file changed

+14
-9
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/BinaryFileResponse.php
+14-9Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ class BinaryFileResponse extends Response
2727
{
2828
protected static $trustXSendfileTypeHeader = false;
2929

30+
/**
31+
* @var File
32+
*/
3033
protected $file;
3134
protected $offset;
3235
protected $maxlen;
@@ -179,7 +182,7 @@ public function prepare(Request $request)
179182
$this->headers->set('Content-Type', $this->file->getMimeType() ?: 'application/octet-stream');
180183
}
181184

182-
if ('HTTP/1.0' != $request->server->get('SERVER_PROTOCOL')) {
185+
if ('HTTP/1.0' !== $request->server->get('SERVER_PROTOCOL')) {
183186
$this->setProtocolVersion('1.1');
184187
}
185188

@@ -196,17 +199,17 @@ public function prepare(Request $request)
196199
if (false === $path) {
197200
$path = $this->file->getPathname();
198201
}
199-
if (strtolower($type) == 'x-accel-redirect') {
202+
if (strtolower($type) === 'x-accel-redirect') {
200203
// Do X-Accel-Mapping substitutions.
201204
// @link http://wiki.nginx.org/X-accel#X-Accel-Redirect
202205
foreach (explode(',', $request->headers->get('X-Accel-Mapping', '')) as $mapping) {
203206
$mapping = explode('=', $mapping, 2);
204207

205-
if (2 == count($mapping)) {
208+
if (2 === count($mapping)) {
206209
$pathPrefix = trim($mapping[0]);
207210
$location = trim($mapping[1]);
208211

209-
if (substr($path, 0, strlen($pathPrefix)) == $pathPrefix) {
212+
if (substr($path, 0, strlen($pathPrefix)) === $pathPrefix) {
210213
$path = $location.substr($path, strlen($pathPrefix));
211214
break;
212215
}
@@ -217,7 +220,7 @@ public function prepare(Request $request)
217220
$this->maxlen = 0;
218221
} elseif ($request->headers->has('Range')) {
219222
// Process the range headers.
220-
if (!$request->headers->has('If-Range') || $this->getEtag() == $request->headers->get('If-Range')) {
223+
if (!$request->headers->has('If-Range') || $this->getEtag() === $request->headers->get('If-Range')) {
221224
$range = $request->headers->get('Range');
222225
$fileSize = $this->file->getSize();
223226

@@ -252,17 +255,17 @@ public function prepare(Request $request)
252255

253256
/**
254257
* Sends the file.
258+
*
259+
* {@inheritdoc}
255260
*/
256261
public function sendContent()
257262
{
258263
if (!$this->isSuccessful()) {
259-
parent::sendContent();
260-
261-
return;
264+
return parent::sendContent();
262265
}
263266

264267
if (0 === $this->maxlen) {
265-
return;
268+
return $this;
266269
}
267270

268271
$out = fopen('php://output', 'wb');
@@ -272,6 +275,8 @@ public function sendContent()
272275

273276
fclose($out);
274277
fclose($file);
278+
279+
return $this;
275280
}
276281

277282
/**

0 commit comments

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