2121use CodeIgniter \HTTP \RedirectResponse ;
2222use CodeIgniter \HTTP \Request ;
2323use CodeIgniter \HTTP \RequestInterface ;
24- use CodeIgniter \HTTP \Response ;
2524use CodeIgniter \HTTP \ResponseInterface ;
2625use CodeIgniter \HTTP \URI ;
2726use CodeIgniter \Router \Exceptions \RedirectException ;
@@ -297,7 +296,7 @@ protected function initializeKint()
297296 * @param RouteCollectionInterface|null $routes
298297 * @param boolean $returnResponse
299298 *
300- * @return boolean|RequestInterface|Response| ResponseInterface|mixed
299+ * @return boolean|RequestInterface|ResponseInterface|mixed
301300 * @throws RedirectException
302301 * @throws Exception
303302 */
@@ -378,7 +377,7 @@ public function useSafeOutput(bool $safe = true)
378377 * @param Cache $cacheConfig
379378 * @param boolean $returnResponse
380379 *
381- * @return RequestInterface|\CodeIgniter\HTTP\Response| ResponseInterface|mixed
380+ * @return RequestInterface|ResponseInterface|mixed
382381 * @throws RedirectException
383382 */
384383 protected function handleRequest (RouteCollectionInterface $ routes = null , Cache $ cacheConfig , bool $ returnResponse = false )
@@ -401,15 +400,12 @@ protected function handleRequest(RouteCollectionInterface $routes = null, Cache
401400 // Never run filters when running through Spark cli
402401 if (! defined ('SPARKED ' ))
403402 {
404- $ possibleRedirect = $ filters ->run ($ uri , 'before ' );
405- if ($ possibleRedirect instanceof RedirectResponse)
406- {
407- return $ possibleRedirect ->send ();
408- }
409- // If a Response instance is returned, the Response will be sent back to the client and script execution will stop
410- if ($ possibleRedirect instanceof ResponseInterface)
403+ $ possibleResponse = $ filters ->run ($ uri , 'before ' );
404+
405+ // If a ResponseInterface instance is returned then send it back to the client and stop
406+ if ($ possibleResponse instanceof ResponseInterface)
411407 {
412- return $ possibleRedirect ->send ();
408+ return $ returnResponse ? $ possibleResponse : $ possibleResponse -> pretend ( $ this -> useSafeOutput ) ->send ();
413409 }
414410 }
415411
@@ -454,7 +450,7 @@ protected function handleRequest(RouteCollectionInterface $routes = null, Cache
454450 }
455451 }
456452
457- if ($ response instanceof Response )
453+ if ($ response instanceof ResponseInterface )
458454 {
459455 $ this ->response = $ response ;
460456 }
@@ -1038,7 +1034,7 @@ protected function gatherOutput(Cache $cacheConfig = null, $returned = null)
10381034 // echoed already.
10391035 // We also need to save the instance locally
10401036 // so that any status code changes, etc, take place.
1041- if ($ returned instanceof Response )
1037+ if ($ returned instanceof ResponseInterface )
10421038 {
10431039 $ this ->response = $ returned ;
10441040 $ returned = $ returned ->getBody ();
0 commit comments