Skip to content

Conversation

BlackbitDevs
Copy link

When you want to send headers before request finishes via

class MyController  {
  public function myAction() {
      $response = new Response();
      $response->headers->set(
          'Content-Disposition',
          HeaderUtils::makeDisposition(
              HeaderUtils::DISPOSITION_ATTACHMENT,
              'file.txt
          )
      );
      
      $response->sendHeaders();
      ob_flush();
      flush();

      // do some work to populate response
      sleep(5); // this is only for demonstraton purposes

      return $response;
  }
}

I get a warning error

E_WARNING: Cannot modify header information - headers already sent in [Root folder]/vendor/symfony/http-foundation/Session/SessionUtils.php, line 54

With this PR the headers get only manipulated during kernel.response event if the headers have ot already been sent.

@symfony-bot
Copy link

symfony-bot bot commented Feb 15, 2022

Thanks for your pull request! We love contributions.

However, this repository is what we call a "subtree split": a read-only copy of one directory of the main Symfony repository. It is used by Composer to allow developers to depend on specific Symfony components.

If you want to contribute, you should instead open a pull request on the main repository:

https://github.com/symfony/symfony

Thank you for your contribution!

PS: if you haven't already, please add tests, and beware that bug fixes should be submitted on the lowest maintained branch where they apply.

@BlackbitDevs
Copy link
Author

Closed in favor of symfony/symfony#45434

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant