Skip to content

Commit c1a1a1f

Browse files
kenjisMGatner
authored andcommitted
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 9c0c695 commit c1a1a1f

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

system/CodeIgniter.php

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -489,20 +489,26 @@ protected function handleRequest(?RouteCollectionInterface $routes, Cache $cache
489489
$this->response = $response;
490490
}
491491

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-
}
492+
// Skip unnecessary processing for special Responses.
493+
if (! $response instanceof DownloadResponse && ! $response instanceof RedirectResponse) {
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+
$body = $this->response->getBody();
503+
if ($body !== null) {
504+
$output = $this->displayPerformanceMetrics($body);
505+
$this->response->setBody($output);
506+
}
502507

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));
508+
// Save our current URI as the previous URI in the session
509+
// for safer, more accurate use with `previous_url()` helper function.
510+
$this->storePreviousURL(current_url(true));
511+
}
506512

507513
unset($uri);
508514

0 commit comments

Comments
 (0)