Redirect::intended() behavior
After a user logs in I use Redirect::intended with secure parameter set to false:
Redirect::intended('my fallback url', 302, array(), false)
Most of my site is http, not https, so it is desirable to send all "intended" requests to an http url (hence using secure=false parameter), and let auth filter catch/redirect any urls that are required to be secure (https).
Currently in UriGenerator.php we have the following:
public function to($path, $extra = array(), $secure = null)
{
// First we will check if the URL is already a valid URL. If it is we will not
// try to generate a new one but will simply return the URL as is, which is
// convenient since developers do not always have to check if it's valid.
if ($this->isValidUrl($path)) return $path;
$scheme = $this->getScheme($secure);
$tail = implode('/', array_map(
'rawurlencode', (array) $extra)
);
// Once we have the scheme we will compile the "tail" by collapsing the values
// into a single string delimited by slashes. This just makes it convenient
// for passing the array of parameters to this URL as a list of segments.
$root = $this->getRootUrl($scheme);
return $this->trimUrl($root, $path, $tail);
}
With Redirect::intended(), the following condition always evaluates to true:
$this->isValidUrl($path)
So, the secure argument has no effect because the scheme is never changed from https to http. It would seem more intuitive to have some version of the following:
if ($this->isValidUrl($path)) {
if(!is_null($secure)) {
// modify $path scheme based on $secure value first
if($secure & starts_with($path, 'http://')) {
$path = 'https://' . substr($path, 8);
}
if(!$secure & starts_with($path, 'https://')) {
$path = 'http://' . substr($path, 8);
}
}
return $path;
}
Yes, intended basically sends you to the full URL they were trying to access. So, it will use whatever scheme they tried to access.
Since you've provided the secure parameter, I expected Redirect::intended to abide by that parameter's value regardless of the scheme provided by the user. That behavior seems intuitive to me, that's all. In any case, thanks.