Skip to content

Commit 62d411e

Browse files
committed
fix: Response::download() causes TypeError
TypeError CodeIgniter\CodeIgniter::displayPerformanceMetrics(): Argument #1 ($output) must be of type string, null given, called in .../CodeIgniter4/system/CodeIgniter.php on line 500
1 parent 2da8ef8 commit 62d411e

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

system/CodeIgniter.php

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -485,24 +485,27 @@ protected function handleRequest(?RouteCollectionInterface $routes, Cache $cache
485485
}
486486
}
487487

488-
if ($response instanceof ResponseInterface) {
489-
$this->response = $response;
490-
}
488+
// Skip unnecessary processing for the DownloadResponse.
489+
if (! $response instanceof DownloadResponse) {
490+
if ($response instanceof ResponseInterface) {
491+
$this->response = $response;
492+
}
491493

492-
// Cache it without the performance metrics replaced
493-
// so that we can have live speed updates along the way.
494-
// Must be run after filters to preserve the Response headers.
495-
if (static::$cacheTTL > 0) {
496-
$this->cachePage($cacheConfig);
497-
}
494+
// Cache it without the performance metrics replaced
495+
// so that we can have live speed updates along the way.
496+
// Must be run after filters to preserve the Response headers.
497+
if (static::$cacheTTL > 0) {
498+
$this->cachePage($cacheConfig);
499+
}
498500

499-
// Update the performance metrics
500-
$output = $this->displayPerformanceMetrics($this->response->getBody());
501-
$this->response->setBody($output);
501+
// Update the performance metrics
502+
$output = $this->displayPerformanceMetrics($this->response->getBody());
503+
$this->response->setBody($output);
502504

503-
// Save our current URI as the previous URI in the session
504-
// for safer, more accurate use with `previous_url()` helper function.
505-
$this->storePreviousURL(current_url(true));
505+
// Save our current URI as the previous URI in the session
506+
// for safer, more accurate use with `previous_url()` helper function.
507+
$this->storePreviousURL(current_url(true));
508+
}
506509

507510
unset($uri);
508511

0 commit comments

Comments
 (0)