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

Skip to content

[HttpFoundation] moved file hash calculation to own method #6708

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/Symfony/Component/HttpFoundation/BinaryFileResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* @author Igor Wiedler <[email protected]>
* @author Jordan Alliot <[email protected]>
* @author Sergey Linnik <[email protected]>
* @author Povilas Skruibis <[email protected]>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tobion I thought its mandatory if you touch the file. If it's not, I can make PR to remove it.

*/
class BinaryFileResponse extends Response
{
Expand Down Expand Up @@ -123,11 +124,23 @@ public function setAutoLastModified()
*/
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.
*
Expand Down