Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Fix BinaryFileResponse sending wrong Content-Length header for files modified by stream wrappers/filters#19740

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
TravisCarden wants to merge2 commits intosymfony:2.7fromTravisCarden:19738

Conversation

@TravisCarden
Copy link
Contributor

QA
Branch?2.7
Bug fix?yes
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes/no
Fixed tickets#19738
LicenseMIT
Doc PRreference to the documentation PR, if any

I have attempted to followthe guidelines for submitting a patch, but this is my first attempt to the contribute to the Symfony community, so I welcome feedback. Thanks.

@fabpot
Copy link
Member

@TravisCarden You did very well :) What about the suggestion made by@EclipseGc on the linked ticket? It looks like a better way to me at first glance.

@TravisCarden
Copy link
ContributorAuthor

Sure. As long as no client code depends on\Symfony\Component\HttpFoundation\File\File::getSize() returning the file size on disk specifically, then fixing the problem there solves at a higher level of abstraction. Updating PR...

// Get the file size from a stream rather than from disk in case it is changed later by
// stream wrappers or stream filters.
$file =fopen($this->getPathname(),'rb');
$fstat =fstat($file);

Choose a reason for hiding this comment

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

can't we callstat($this->getPathname()) directly instead?

Choose a reason for hiding this comment

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

ok, just read your linked issue.
any way to add a test case that would break when using the parent getSize()?

Choose a reason for hiding this comment

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

To do that I think we'd need to write a test that is actually encrypting files so that the size is different on disc. I assume that's the best way to go about doing this?

…h header for files modified by stream wrappers/filters.
@TravisCarden
Copy link
ContributorAuthor

I was going to write a unit test for this, but I can't install the project dependencies on the 2.7 branch:

$ composer updateLoading composer repositories with package informationUpdating dependencies (including require-dev)Your requirements could not be resolved to an installable set of packages.

Any thoughts?

@jakzal
Copy link
Contributor

@TravisCarden works for me. Have you updated composer.json by any chance?

@TravisCarden
Copy link
ContributorAuthor

TravisCarden commentedSep 19, 2016
edited
Loading

I've got it working now. Not sure what was actually wrong, since I didn't change anything today. We'll chalk it up to gremlins. Thanks,@jakzal

@TravisCardenTravisCardenforce-pushed the19738 branch 5 times, most recently fromb5d8d75 to126b8acCompareSeptember 20, 2016 03:15
@TravisCarden
Copy link
ContributorAuthor

Okay, here's an example of a unit test that fails without the patch and passes with it. It involves an annoyingly large fixture for such a small change, because it requires a stream filter, which in turn necessitates a stream wrapper; and I wasn't sure where those classes should go in the directory structure. They didn't get autoloaded in the test where I put them (hence the@todo), and I didn't have time to look into it. It may be necessary to more fully implement the stream wrapper to prevent a fragile test. In any case, this gets the ball rolling. I would love feedback.

// reliable way to get the effective size of the file is to actually read it.
ob_start();
$size =readfile($this->getPathname());
ob_end_clean();

Choose a reason for hiding this comment

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

This will load the full response in memory, which means will break for contents that don't fit into memory.
This totally defeat the purpose of using streams imho.
When a stream wrapper/filter is there, we'd better use chunked encoding.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

You seem to be correct, of course. I think the code worked in the context of my project on account of incidental configuration details, but considering the matter abstractly it obviously doesn't seem like a solution suitable for generic application. Using chunked encoding in case of a wrapper/filter does seem like a sensible approach. I don't know what that would look like, though.

@nicolas-grekas
Copy link
Member

nicolas-grekas commentedOct 3, 2016
edited
Loading

To switch chunked encoding on, one shouldnot send theContent-Length header.
I think we can solve this issue by makinggetSize returnfalse when a filter/wrapper is at use, and handle thatfalse inBinaryFileResponse.

@nicolas-grekas
Copy link
Member

Since it's impossible to know if a stream has a filter attached to it, the only solution is to make authors responsible for saying it. This is what#21188 tries to achieve. Closing this one.

fabpot added a commit that referenced this pull requestJan 9, 2017
…ryFileResponse (nicolas-grekas)This PR was merged into the 3.3-dev branch.Discussion----------[HttpFoundation] Add File\Stream for size-unknown BinaryFileResponse| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets |#19738| License       | MIT| Doc PR        |symfony/symfony-docs#7343Replaces#19740. Native "getSize" is reported to return false on error, so using false as return type doesn't break the signature.Commits-------8011209 [HttpFoundation] Add File\Stream for size-unknown BinaryFileResponse
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

Assignees

No one assigned

Projects

None yet

Milestone

2.7

Development

Successfully merging this pull request may close these issues.

6 participants

@TravisCarden@fabpot@jakzal@nicolas-grekas@EclipseGc@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp