diff --git a/flight/Engine.php b/flight/Engine.php index ffd51e4..2d46349 100644 --- a/flight/Engine.php +++ b/flight/Engine.php @@ -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(); + } } /** diff --git a/tests/server/LayoutMiddleware.php b/tests/server/LayoutMiddleware.php index bb30bda..7be2cda 100644 --- a/tests/server/LayoutMiddleware.php +++ b/tests/server/LayoutMiddleware.php @@ -72,6 +72,9 @@ class LayoutMiddleware
  • 404 Not Found
  • Mega group
  • Error
  • +
  • JSON
  • +
  • Halt
  • +
  • Redirect
  • HTML; echo '
    '; diff --git a/tests/server/index.php b/tests/server/index.php index b3d5230..236ad31 100644 --- a/tests/server/index.php +++ b/tests/server/index.php @@ -23,6 +23,9 @@ Flight::group('', function () { // Test 1: Root route Flight::route('/', function () { echo 'Route text: Root route works!'; + if(Flight::request()->query->redirected) { + echo '
    Redirected from /redirect route successfully!'; + } }); Flight::route('/querytestpath', function () { echo 'Route text: This ir query route
    '; @@ -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( '

    500 Internal Server Error

    ' .