Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b2bcbbb

Browse files
committed
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?
2 parents c5fcf0d + a923849 commit b2bcbbb

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/Symfony/Component/HttpFoundation/BinaryFileResponse.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* @author Igor Wiedler <[email protected]>
2323
* @author Jordan Alliot <[email protected]>
2424
* @author Sergey Linnik <[email protected]>
25+
* @author Povilas Skruibis <[email protected]>
2526
*/
2627
class BinaryFileResponse extends Response
2728
{
@@ -123,11 +124,23 @@ public function setAutoLastModified()
123124
*/
124125
public function setAutoEtag()
125126
{
126-
$this->setEtag(sha1_file($this->file->getPathname()));
127+
$this->setEtag($this->calculateFileHash($this->file->getPathname()));
127128

128129
return $this;
129130
}
130131

132+
/**
133+
* Calculate file hash
134+
*
135+
* @param string $filename The path to the file
136+
*
137+
* @return string
138+
*/
139+
protected function calculateFileHash($filename)
140+
{
141+
return sha1_file($filename);
142+
}
143+
131144
/**
132145
* Sets the Content-Disposition header with the given filename.
133146
*

0 commit comments

Comments
 (0)