• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

codeigniter4 / CodeIgniter4 / 37986190232

09 Oct 2026 08:19PM UTC coverage: 50.703% (-39.5%) from 90.183%
37986190232

Pull #10606

github

web-flow
Merge 2cebb1efa into 7822cde17
Pull Request #10606: fix: refresh REQUEST after URI GET normalization

17 of 30 new or added lines in 2 files covered. (56.67%)

10012 existing lines in 288 files now uncovered.

12871 of 25385 relevant lines covered (50.7%)

87.05 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

50.0
/system/HTTP/Exceptions/RedirectException.php
1
<?php
2

3
declare(strict_types=1);
4

5
/**
6
 * This file is part of CodeIgniter 4 framework.
7
 *
8
 * (c) CodeIgniter Foundation <admin@codeigniter.com>
9
 *
10
 * For the full copyright and license information, please view
11
 * the LICENSE file that was distributed with this source code.
12
 */
13

14
namespace CodeIgniter\HTTP\Exceptions;
15

16
use CodeIgniter\Exceptions\HTTPExceptionInterface;
17
use CodeIgniter\Exceptions\InvalidArgumentException;
18
use CodeIgniter\Exceptions\LogicException;
19
use CodeIgniter\Exceptions\RuntimeException;
20
use CodeIgniter\HTTP\ResponsableInterface;
21
use CodeIgniter\HTTP\ResponseInterface;
22
use Throwable;
23

24
/**
25
 * RedirectException
26
 */
27
class RedirectException extends RuntimeException implements ExceptionInterface, ResponsableInterface, HTTPExceptionInterface
28
{
29
    /**
30
     * HTTP status code for redirects
31
     *
32
     * @var int
33
     */
34
    protected $code = 302;
35

36
    protected ?ResponseInterface $response = null;
37

38
    /**
39
     * @param ResponseInterface|string $message Response object or a string containing a relative URI.
40
     * @param int                      $code    HTTP status code to redirect if $message is a string.
41
     */
42
    public function __construct($message = '', int $code = 0, ?Throwable $previous = null)
43
    {
44
        if (! is_string($message) && ! $message instanceof ResponseInterface) {
2 ✔
45
            throw new InvalidArgumentException(
×
46
                'RedirectException::__construct() first argument must be a string or ResponseInterface',
×
47
                0,
×
48
                $this,
×
49
            );
×
50
        }
51

52
        if ($message instanceof ResponseInterface) {
2 ✔
53
            $this->response = $message;
2 ✔
54

55
            $message = '';
2 ✔
56

57
            if ($this->response->getHeaderLine('Location') === '' && $this->response->getHeaderLine('Refresh') === '') {
2 ✔
UNCOV
58
                throw new LogicException(
×
UNCOV
59
                    'The Response object passed to RedirectException does not contain a redirect address.',
×
UNCOV
60
                );
×
61
            }
62

63
            if ($this->response->getStatusCode() < 301 || $this->response->getStatusCode() > 308) {
2 ✔
UNCOV
64
                $this->response->setStatusCode($this->code);
×
65
            }
66
        }
67

68
        parent::__construct($message, $code, $previous);
2 ✔
69
    }
70

71
    public function getResponse(): ResponseInterface
72
    {
73
        if (! $this->response instanceof ResponseInterface) {
2 ✔
UNCOV
74
            $this->response = service('response')->redirect(
×
UNCOV
75
                base_url($this->getMessage()),
×
UNCOV
76
                'auto',
×
UNCOV
77
                $this->getCode(),
×
UNCOV
78
            );
×
79
        }
80

81
        $location = $this->response->getHeaderLine('Location');
2 ✔
82

83
        service('logger')->info(sprintf(
2 ✔
84
            'REDIRECTED ROUTE at %s',
2 ✔
85
            $location !== '' ? $location : substr($this->response->getHeaderLine('Refresh'), 6),
2 ✔
86
        ));
2 ✔
87

88
        return $this->response;
2 ✔
89
    }
90
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc