fix for JSON in v3 output buffering

pull/551/head
n0nag0n 11 months ago
parent 5073758cfa
commit d8aa490dbd

@ -742,8 +742,10 @@ class Engine
$this->response()
->status($code)
->header('Content-Type', 'application/json; charset=' . $charset)
->write($json)
->send();
->write($json);
if($this->response()->v2_output_buffering === true) {
$this->response()->send();
}
}
/**

@ -72,6 +72,9 @@ class LayoutMiddleware
<li><a href="/postpage">404 Not Found</a></li>
<li><a href="{$final_route}">Mega group</a></li>
<li><a href="/error">Error</a></li>
<li><a href="/json">JSON</a></li>
<li><a href="/halt">Halt</a></li>
<li><a href="/redirect">Redirect</a></li>
</ul>
HTML;
echo '<div id="container">';

@ -23,6 +23,9 @@ Flight::group('', function () {
// Test 1: Root route
Flight::route('/', function () {
echo '<span id="infotext">Route text:</span> Root route works!';
if(Flight::request()->query->redirected) {
echo '<br>Redirected from /redirect route successfully!';
}
});
Flight::route('/querytestpath', function () {
echo '<span id="infotext">Route text:</span> This ir query route<br>';
@ -95,8 +98,25 @@ Flight::group('', function () {
Flight::route('/error', function () {
trigger_error('This is a successful error');
});
// Test 10: Halt
Flight::route('/halt', function() {
Flight::halt(400, 'Halt worked successfully');
});
}, [ new LayoutMiddleware() ]);
// Test 9: JSON output
Flight::route('/json', function() {
Flight::json(['message' => 'JSON renders successfully!']);
});
// Test 11: Redirect
Flight::route('/redirect', function() {
Flight::redirect('/?redirected=1');
});
Flight::map('error', function (Throwable $e) {
echo sprintf(
'<h1>500 Internal Server Error</h1>' .

Loading…
Cancel
Save