{"action":"created","issue":{"url":"https://api.github.com/repos/symfony/symfony/issues/28237","repository_url":"https://api.github.com/repos/symfony/symfony","labels_url":"https://api.github.com/repos/symfony/symfony/issues/28237/labels{/name}","comments_url":"https://api.github.com/repos/symfony/symfony/issues/28237/comments","events_url":"https://api.github.com/repos/symfony/symfony/issues/28237/events","html_url":"https://github.com/symfony/symfony/issues/28237","id":352848401,"node_id":"MDU6SXNzdWUzNTI4NDg0MDE=","number":28237,"title":"BinaryFileResponse doesn't work unless prepare is called","user":{"login":"iluuu1994","id":1752683,"node_id":"MDQ6VXNlcjE3NTI2ODM=","avatar_url":"https://avatars3.githubusercontent.com/u/1752683?v=4","gravatar_id":"","url":"https://api.github.com/users/iluuu1994","html_url":"https://github.com/iluuu1994","followers_url":"https://api.github.com/users/iluuu1994/followers","following_url":"https://api.github.com/users/iluuu1994/following{/other_user}","gists_url":"https://api.github.com/users/iluuu1994/gists{/gist_id}","starred_url":"https://api.github.com/users/iluuu1994/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iluuu1994/subscriptions","organizations_url":"https://api.github.com/users/iluuu1994/orgs","repos_url":"https://api.github.com/users/iluuu1994/repos","events_url":"https://api.github.com/users/iluuu1994/events{/privacy}","received_events_url":"https://api.github.com/users/iluuu1994/received_events","type":"User","site_admin":false},"labels":[{"id":100079,"node_id":"MDU6TGFiZWwxMDAwNzk=","url":"https://api.github.com/repos/symfony/symfony/labels/Bug","name":"Bug","color":"e10c02","default":false},{"id":125366,"node_id":"MDU6TGFiZWwxMjUzNjY=","url":"https://api.github.com/repos/symfony/symfony/labels/HttpFoundation","name":"HttpFoundation","color":"DDDDDD","default":false},{"id":237003792,"node_id":"MDU6TGFiZWwyMzcwMDM3OTI=","url":"https://api.github.com/repos/symfony/symfony/labels/Status:%20Needs%20Review","name":"Status: Needs Review","color":"ededed","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-08-22T08:17:05Z","updated_at":"2018-08-24T21:29:21Z","closed_at":null,"author_association":"NONE","body":"**Symfony version(s) affected**: 3.4.14\r\n\r\n**Description**  \r\n\r\nI'm using the **HttpFoundation** component to stream binary files. I'm using the basic snipped underneath which produces no output. The reason for this is [this line](https://github.com/symfony/symfony/blob/3.4/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php#L303).\r\n\r\n`stream_copy_to_stream` has the following signature:\r\n\r\n```php\r\nint stream_copy_to_stream(resource $source, resource $dest[, int $maxlength = -1[, int $offset = 0]])\r\n```\r\n\r\nThe `maxlen` and `offset` properties are only actually ever set in the `prepare` method. Thus Symfony passes `null` to both of these parameters unless `prepared` is called. PHP will not do anything if these properties are null:\r\n\r\nhttps://3v4l.org/MtBl7\r\n\r\n**How to reproduce**  \r\n\r\n```php\r\n$response = new BinaryFileResponse($filepath);\r\n$response->send();\r\n```\r\n\r\n**Possible Solution**  \r\n\r\nThe solution is to call `prepare` on the response. However, this is not stated \r\n\r\n```php\r\n$response = new BinaryFileResponse($filepath);\r\n$response->prepare(Request::createFromGlobals());\r\n$response->send();\r\n```\r\n\r\nSymfony should either:\r\n\r\n* Be clearer in the documentation that `prepare` is necessary\r\n* Throw an error when `maxlength` or `offset` are null\r\n* Default to `-1` and `0` as the default values"},"comment":{"url":"https://api.github.com/repos/symfony/symfony/issues/comments/415887449","html_url":"https://github.com/symfony/symfony/issues/28237#issuecomment-415887449","issue_url":"https://api.github.com/repos/symfony/symfony/issues/28237","id":415887449,"node_id":"MDEyOklzc3VlQ29tbWVudDQxNTg4NzQ0OQ==","user":{"login":"iluuu1994","id":1752683,"node_id":"MDQ6VXNlcjE3NTI2ODM=","avatar_url":"https://avatars3.githubusercontent.com/u/1752683?v=4","gravatar_id":"","url":"https://api.github.com/users/iluuu1994","html_url":"https://github.com/iluuu1994","followers_url":"https://api.github.com/users/iluuu1994/followers","following_url":"https://api.github.com/users/iluuu1994/following{/other_user}","gists_url":"https://api.github.com/users/iluuu1994/gists{/gist_id}","starred_url":"https://api.github.com/users/iluuu1994/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iluuu1994/subscriptions","organizations_url":"https://api.github.com/users/iluuu1994/orgs","repos_url":"https://api.github.com/users/iluuu1994/repos","events_url":"https://api.github.com/users/iluuu1994/events{/privacy}","received_events_url":"https://api.github.com/users/iluuu1994/received_events","type":"User","site_admin":false},"created_at":"2018-08-24T21:29:21Z","updated_at":"2018-08-24T21:29:21Z","author_association":"NONE","body":"@wackymole When using the Symfony kernel Symfony will always calls `prepare` on the response under the hood.:\r\n\r\nhttps://github.com/symfony/symfony/blob/4e4b21668a9594ddcbbd67f2be55f733178dde28/src/Symfony/Component/HttpKernel/EventListener/ResponseListener.php#L47\r\n\r\nI'm using the `BinaryFileResponse` in a non Symfony project. Try just the `send` but without `prepare`."}}
{"actor":{"display_login":"iluuu1994"}}