Skip to content

Commit

Permalink
bug #17757 [HttpFoundation] BinaryFileResponse sendContent return as …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
fabpot committed Feb 11, 2016
2 parents bb85161 + 120dfe4 commit 730a472
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/Symfony/Component/HttpFoundation/BinaryFileResponse.php
Expand Up @@ -27,6 +27,9 @@ class BinaryFileResponse extends Response
{
protected static $trustXSendfileTypeHeader = false;

/**
* @var File
*/
protected $file;
protected $offset;
protected $maxlen;
Expand Down Expand Up @@ -179,7 +182,7 @@ public function prepare(Request $request)
$this->headers->set('Content-Type', $this->file->getMimeType() ?: 'application/octet-stream');
}

if ('HTTP/1.0' != $request->server->get('SERVER_PROTOCOL')) {
if ('HTTP/1.0' !== $request->server->get('SERVER_PROTOCOL')) {
$this->setProtocolVersion('1.1');
}

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

if (2 == count($mapping)) {
if (2 === count($mapping)) {
$pathPrefix = trim($mapping[0]);
$location = trim($mapping[1]);

if (substr($path, 0, strlen($pathPrefix)) == $pathPrefix) {
if (substr($path, 0, strlen($pathPrefix)) === $pathPrefix) {
$path = $location.substr($path, strlen($pathPrefix));
break;
}
Expand All @@ -217,7 +220,7 @@ public function prepare(Request $request)
$this->maxlen = 0;
} elseif ($request->headers->has('Range')) {
// Process the range headers.
if (!$request->headers->has('If-Range') || $this->getEtag() == $request->headers->get('If-Range')) {
if (!$request->headers->has('If-Range') || $this->getEtag() === $request->headers->get('If-Range')) {
$range = $request->headers->get('Range');
$fileSize = $this->file->getSize();

Expand Down Expand Up @@ -252,17 +255,17 @@ public function prepare(Request $request)

/**
* Sends the file.
*
* {@inheritdoc}
*/
public function sendContent()
{
if (!$this->isSuccessful()) {
parent::sendContent();

return;
return parent::sendContent();
}

if (0 === $this->maxlen) {
return;
return $this;
}

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

fclose($out);
fclose($file);

return $this;
}

/**
Expand Down

0 comments on commit 730a472

Please sign in to comment.