File tree Expand file tree Collapse file tree 2 files changed +26
-4
lines changed
src/Symfony/Component/HttpKernel Expand file tree Collapse file tree 2 files changed +26
-4
lines changed Original file line number Diff line number Diff line change @@ -181,10 +181,19 @@ protected function filterFiles(array $files): array
181181 protected function filterResponse (object $ response ): DomResponse
182182 {
183183 // this is needed to support StreamedResponse
184- ob_start () ;
185- $ response -> sendContent ();
186- $ content = ob_get_clean () ;
184+ $ content = '' ;
185+ ob_start ( static function ( string $ chunk ) use (& $ content ): string {
186+ $ content .= $ chunk ;
187187
188- return new DomResponse ($ content , $ response ->getStatusCode (), $ response ->headers ->all ());
188+ return $ chunk ;
189+ });
190+
191+ try {
192+ $ response ->sendContent ();
193+
194+ return new DomResponse ($ content , $ response ->getStatusCode (), $ response ->headers ->all ());
195+ } finally {
196+ ob_end_clean ();
197+ }
189198 }
190199}
Original file line number Diff line number Diff line change @@ -89,6 +89,19 @@ public function testFilterResponseSupportsStreamedResponses()
8989 $ this ->assertEquals ('foo ' , $ domResponse ->getContent ());
9090 }
9191
92+ public function testFilterResponseSupportsStreamedResponsesWithChunks ()
93+ {
94+ $ client = new HttpKernelBrowser (new TestHttpKernel ());
95+
96+ $ r = new \ReflectionObject ($ client );
97+ $ m = $ r ->getMethod ('filterResponse ' );
98+
99+ $ response = new StreamedResponse (new \ArrayIterator (['foo ' ]));
100+
101+ $ domResponse = $ m ->invoke ($ client , $ response );
102+ $ this ->assertEquals ('foo ' , $ domResponse ->getContent ());
103+ }
104+
92105 public function testUploadedFile ()
93106 {
94107 $ source = tempnam (sys_get_temp_dir (), 'source ' );
You can’t perform that action at this time.
0 commit comments