fix for JSON in v3 output buffering

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

@ -742,8 +742,10 @@ class Engine
$this->response() $this->response()
->status($code) ->status($code)
->header('Content-Type', 'application/json; charset=' . $charset) ->header('Content-Type', 'application/json; charset=' . $charset)
->write($json) ->write($json);
->send(); 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="/postpage">404 Not Found</a></li>
<li><a href="{$final_route}">Mega group</a></li> <li><a href="{$final_route}">Mega group</a></li>
<li><a href="/error">Error</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> </ul>
HTML; HTML;
echo '<div id="container">'; echo '<div id="container">';

@ -23,6 +23,9 @@ Flight::group('', function () {
// Test 1: Root route // Test 1: Root route
Flight::route('/', function () { Flight::route('/', function () {
echo '<span id="infotext">Route text:</span> Root route works!'; 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 () { Flight::route('/querytestpath', function () {
echo '<span id="infotext">Route text:</span> This ir query route<br>'; echo '<span id="infotext">Route text:</span> This ir query route<br>';
@ -95,8 +98,25 @@ Flight::group('', function () {
Flight::route('/error', function () { Flight::route('/error', function () {
trigger_error('This is a successful error'); trigger_error('This is a successful error');
}); });
// Test 10: Halt
Flight::route('/halt', function() {
Flight::halt(400, 'Halt worked successfully');
});
}, [ new LayoutMiddleware() ]); }, [ 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) { Flight::map('error', function (Throwable $e) {
echo sprintf( echo sprintf(
'<h1>500 Internal Server Error</h1>' . '<h1>500 Internal Server Error</h1>' .

Loading…
Cancel
Save