Selaa lähdekoodia

[HttpFoundation] prevented Response headers to be sent twice

This change allows for more flexibility if the developer wants to flush
the Response content early (the drawback being that Response listeners
won't be able to tweak the HTTP headers anymore).

There is another benefit: avoid the infamous
"Fatal error: Exception thrown without a stack frame in Unknown on line 0".

Here is a small scenario when this can happen (thanks dtee for identifying this issue):

* Call flush() in controller to output html early, then throw exception
* ExceptionHandler triggers handle() function and return new Response object to output...
* Because the header is sent (flush() call in Controller), php's E_WARNING error get raised, which gets handled by ErrorHandler->handle() and it throws new ErrorException()
* PHP fatals to prevent Exception loop: "Fatal error: Exception thrown without a stack frame in Unknown on line 0"
Fabien Potencier 14 vuotta sitten
vanhempi
commit
bb5075d820
1 muutettua tiedostoa jossa 5 lisäystä ja 0 poistoa
  1. 5 0
      src/Symfony/Component/HttpFoundation/Response.php

+ 5 - 0
src/Symfony/Component/HttpFoundation/Response.php

@@ -119,6 +119,11 @@ class Response
      */
     public function sendHeaders()
     {
+        // headers have already been sent by the developer
+        if (headers_sent()) {
+            return;
+        }
+
         $this->fixContentType();
 
         // status