Skip to content

Commit 6219207

Browse files
committed
Fix warnings when streaming HTML responses are used.
With the advent of streaming responses, some HTML responses will be streamed. DebugKit can't realistically insert itself into these streamed response bodies. Refs #452
1 parent 26123f6 commit 6219207

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/Routing/Filter/DebugBarFilter.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ protected function _injectScripts($id, $response)
233233
return;
234234
}
235235
$body = $response->body();
236+
if (!is_string($body)) {
237+
return;
238+
}
236239
$pos = strrpos($body, '</body>');
237240
if ($pos === false) {
238241
return;

tests/TestCase/Routing/Filter/DebugBarFilterTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,31 @@ public function testAfterDispatchIgnoreRequestAction()
109109
$this->assertNotContains('<script>', $response->body());
110110
}
111111

112+
/**
113+
* Test that afterDispatch ignores streaming bodies
114+
*
115+
* @return void
116+
*/
117+
public function testAfterDispatchIgnoreStreamBodies()
118+
{
119+
$request = new Request([
120+
'url' => '/articles',
121+
'params' => ['plugin' => null]
122+
]);
123+
$response = new Response([
124+
'statusCode' => 200,
125+
'type' => 'text/html',
126+
]);
127+
$response->body(function() {
128+
echo 'I am a teapot!';
129+
});
130+
131+
$bar = new DebugBarFilter($this->events, []);
132+
$event = new Event('Dispatcher.afterDispatch', $bar, compact('request', 'response'));
133+
$this->assertNull($bar->afterDispatch($event));
134+
$this->assertInstanceOf('Closure', $response->body());
135+
}
136+
112137
/**
113138
* Test that afterDispatch saves panel data.
114139
*

0 commit comments

Comments
 (0)