8000 StreamedResponses send response to stdout before $response->send() is called in app.php · Issue #21355 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
StreamedResponses send response to stdout before $response->send() is called in app.php #21355
Closed
@Loupax

Description

@Loupax
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version 3.2.1

Steps to reproduce:

  1. Create a controller that returns a StreamedResponse and create a route to it.
    For example
class DefaultController extends Controller
{
    /**
     * @Route('/example')
     */
    public function downloadSomewhatHugeFileAction()
    {
        $response = new StreamedResponse(function () {
            $response = $this->get('webservice.thingy')->fetch()->getBody();
            while (!$response->eof()) {
                echo $response->read(1);
            }
        });

        $disposition = $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, 'file.csv');
        $response->headers->set('Content-Disposition', $disposition);
        return $response;
    }
}

  1. Change your webapp entry point file to look something like this.
...
$kernel = new AppKernel('dev', true);
$kernel->loadClassCache();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
die('Handled but not sent yet');
$response->send();
$kernel->terminate($request, $response);
  1. Visit your new URL and see the response that you don't get if you returned a Response object instead

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0