merged branch povilas/issue_6101 (PR #6708)

This PR was submitted for the master branch but it was merged into the 2.2 branch instead (closes #6708).

Commits
-------

90a3e7a [HttpFoundation] moved file hash calculation to own method

Discussion
----------

[HttpFoundation] moved file hash calculation to own method

Bug fix: no
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Todo: -
Fixes the following tickets: #6101
License of the code: MIT
Documentation PR: -

This commit adds ability to change default hashing implementation by extending BinaryFileResponse.

---------------------------------------------------------------------------

by stloyd at 2013-01-11T16:23:30Z

IMO it's looks a like overkill...

---------------------------------------------------------------------------

by lsmith77 at 2013-01-11T16:39:33Z

hmm yeah .. seems like something that could be done via inheritance ..

---------------------------------------------------------------------------

by Tobion at 2013-01-11T17:44:29Z

I agree, overriting the method is much simpler solution.

---------------------------------------------------------------------------

by jalliot at 2013-01-11T18:16:04Z

Besides the `$autoetag` variable is false by default so you have to explicitly enable this behavior...

---------------------------------------------------------------------------

by povilas at 2013-01-11T18:39:31Z

@lsmith77, @Tobion,  you mean, just move hash calculation to separate protected method, and when you want to change hashing you must extend BinaryFileResponse?
This commit is contained in:
Fabien Potencier 2013-02-11 12:20:16 +01:00
commit b2bcbbbd19

View File

@ -22,6 +22,7 @@ use Symfony\Component\HttpFoundation\File\Exception\FileException;
* @author Igor Wiedler <igor@wiedler.ch>
* @author Jordan Alliot <jordan.alliot@gmail.com>
* @author Sergey Linnik <linniksa@gmail.com>
* @author Povilas Skruibis <puovils@gmail.com>
*/
class BinaryFileResponse extends Response
{
@ -123,11 +124,23 @@ class BinaryFileResponse extends Response
*/
public function setAutoEtag()
{
$this->setEtag(sha1_file($this->file->getPathname()));
$this->setEtag($this->calculateFileHash($this->file->getPathname()));
return $this;
}
/**
* Calculate file hash
*
* @param string $filename The path to the file
*
* @return string
*/
protected function calculateFileHash($filename)
{
return sha1_file($filename);
}
/**
* Sets the Content-Disposition header with the given filename.
*